-
Notifications
You must be signed in to change notification settings - Fork 1.6k
new lint: absolute symbol path usage #10568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
A-lint
Area: New lints
Comments
Wow, thanks @Centri3 for implementing this lint so quickly! |
d-e-s-o
added a commit
to d-e-s-o/libbpf-rs
that referenced
this issue
Dec 4, 2023
In the past we had many submissions that, for one reason or another, were using absolute paths to functions/constants in a very inconsistent manner. It is not particularly great use of anybody's time pointing these out and it's certainly a job that computers can do better. Clippy folks seem to concur that this can be a useful lint [0] and we got blessed with clippy::absolute_paths. Enable it throughout libbpf-rs and libbpf-cargo and fix all violations. [0] rust-lang/rust-clippy#10568 Signed-off-by: Daniel Müller <[email protected]>
danielocfb
pushed a commit
to libbpf/libbpf-rs
that referenced
this issue
Dec 4, 2023
In the past we had many submissions that, for one reason or another, were using absolute paths to functions/constants in a very inconsistent manner. It is not particularly great use of anybody's time pointing these out and it's certainly a job that computers can do better. Clippy folks seem to concur that this can be a useful lint [0] and we got blessed with clippy::absolute_paths. Enable it throughout libbpf-rs and libbpf-cargo and fix all violations. [0] rust-lang/rust-clippy#10568 Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o
added a commit
to d-e-s-o/blazesym
that referenced
this issue
Dec 26, 2023
In the past we had many submissions that, for one reason or another, were using absolute paths to functions/constants in a very inconsistent manner. It is not particularly great use of anybody's time pointing these out and it's certainly a job that computers can do better. Clippy folks seem to concur that this can be a useful lint [0] and we got blessed with clippy::absolute_paths. Enable it throughout the crate and fix all violations. [0] rust-lang/rust-clippy#10568 Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o
added a commit
to libbpf/blazesym
that referenced
this issue
Dec 26, 2023
In the past we had many submissions that, for one reason or another, were using absolute paths to functions/constants in a very inconsistent manner. It is not particularly great use of anybody's time pointing these out and it's certainly a job that computers can do better. Clippy folks seem to concur that this can be a useful lint [0] and we got blessed with clippy::absolute_paths. Enable it throughout the crate and fix all violations. [0] rust-lang/rust-clippy#10568 Signed-off-by: Daniel Müller <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What it does
We get a lot of contributions that, for one reason or another, reference symbols with absolute paths instead of having a
use
declaration at the top. E.g.,instead of
It's not wrong, of course, and variations are possible. E.g., some projects prefer
use std::cmp;
overuse std::cmp::max
etc. pp.But: I am not aware of a single project that uses absolute style. As such, I think there is value in flagging it (without necessarily suggesting an alternative, given that there is more than one). I would certainly find it useful, as it's cumbersome to point out those cases during review, as opposed to having a machine provide assurance that there are none.
Lint Name
absolute-symbol-path
or perhapssymbol-reference-without-use
Category
style, pedantic
Advantage
Point out inconsistent
use
style. For better or worse, most code bases and guides have explicituse
statements that import relevant symbols, so that they can be used without having to provide an absolute path/full reference to the symbol at each call/use site. Having some symbols use absolute paths in the middle of code while others have explicit imports seems l;ike an inconsistency that, for no good reason, and could give a false impression of what functionality is used by a module when just checkinguse
statements.Drawbacks
I don't believe there are drawbacks, but it's a subjective matter, so there are differing opinions on what folks prefer. Should probably be disabled by default.
That being said, macros should probably be excluded from this lint, as it absolutely makes sense for macros to use absolute imports (and it's even the right thing to do in most cases, but that's a different story).
Example
Could be written as:
The text was updated successfully, but these errors were encountered: