You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes lint names are spelled using dashes, sometimes using underscores. But the two types of syntax are not always interchangeable.
Same problem as with crate names. Similarly unnecessary, confusing, frustrating and dangerous. Similarly not documented anywhere. New to Rust? Lints don't work? Go figure.
Scenario 1
Consider that I have a struct with many bools (let's say for a CLI args with clap crate's derive syntax) and surely Clippy reported it as:
warning: more than 3 bools in a struct
<cut>
= help: consider using a state machine or refactoring bools into two-variant enums
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools
= note: `-W clippy::struct-excessive-bools` implied by `-W clippy::pedantic`
If you have an eye of an eagle, you notice that the URL contains underscored version of the name, but without clippy:: prefix, and the "note" contains dashed version, with prefix.
I have many boolean flags in CLI, so I just want to silence this rule for this struct. I copy the lint name from the note and paste it into the code:
#[allow(clippy::struct-excessive-bools)]
That does not work, because this syntax is incorrect in Rust. The word struct is treated as keyword and the - treated as minus:
error: expected identifier, found keyword `struct`
#[allow(clippy::struct-excessive-bools)]
^^^^^^ expected identifier, found keyword
error: expected one of `(`, `,`, `::`, or `=`, found `-`
#[allow(clippy::struct-excessive-bools)]
^ expected one of `(`, `,`, `::`, or `=`
For a newcomer to Rust, no matter how experienced the programmer is, nothing hints at this point that I need to change dashes to underscores. And even if I figured that two syntaxes exist, and I readg docs for Clippy rules sometimes, I still need to manually swap dashes to underscores every time.
Scenario 2
Another problem is that it's impossible to find the rules in the codebase: .cargo/congig.toml and CLI args can contain either syntax, so you cannot just search for one or the other, you need to search both.
Suggestion
I'd like to suggest to consider enforcing underscore syntax and deprecating and dropping the dash syntax. The earlier the better. Clocks are ticking and people are writing more and more pesky dashes, even right now as you read this.
Concrete proposals
Soon:
document the inconsistency in highly visible places
publicly deprecate usage of hyphens (dashes) in lint names
in errors, warnings and suggestions only emit versions with underscores (that's where people are copying them from)
Description
Sometimes lint names are spelled using dashes, sometimes using underscores. But the two types of syntax are not always interchangeable.
Same problem as with crate names. Similarly unnecessary, confusing, frustrating and dangerous. Similarly not documented anywhere. New to Rust? Lints don't work? Go figure.
Scenario 1
Consider that I have a struct with many bools (let's say for a CLI args with
clap
crate's derive syntax) and surely Clippy reported it as:If you have an eye of an eagle, you notice that the URL contains underscored version of the name, but without
clippy::
prefix, and the "note" contains dashed version, with prefix.I have many boolean flags in CLI, so I just want to silence this rule for this struct. I copy the lint name from the note and paste it into the code:
#[allow(clippy::struct-excessive-bools)]
That does not work, because this syntax is incorrect in Rust. The word
struct
is treated as keyword and the-
treated as minus:For a newcomer to Rust, no matter how experienced the programmer is, nothing hints at this point that I need to change dashes to underscores. And even if I figured that two syntaxes exist, and I readg docs for Clippy rules sometimes, I still need to manually swap dashes to underscores every time.
Scenario 2
Another problem is that it's impossible to find the rules in the codebase:
.cargo/congig.toml
and CLI args can contain either syntax, so you cannot just search for one or the other, you need to search both.Suggestion
I'd like to suggest to consider enforcing underscore syntax and deprecating and dropping the dash syntax. The earlier the better. Clocks are ticking and people are writing more and more pesky dashes, even right now as you read this.
Concrete proposals
Soon:
In the next major version:
See also
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: