-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add a "more granular lint groups" page to the book #13501
base: master
Are you sure you want to change the base?
Conversation
@@ -38,6 +38,7 @@ serde_json = "1.0.122" | |||
toml = "0.7.3" | |||
walkdir = "2.3" | |||
filetime = "0.2.9" | |||
indoc = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy_dev also has this as a dependency fwiw, but I can also drop it since it's only used to avoid having to have awkward indentation in one of the format strings
@@ -0,0 +1,219 @@ | |||
# More granular lint groups | |||
|
|||
Clippy groups its lints into [9 primary categories](lints.md), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that lints.md
doesn't have the nursery category documented, so that page actually only describes 8
or has remaining debugging artifacts. | ||
|
||
<!-- lint-group-start: debugging --> | ||
Lints: `dbg_macro`, `todo`, `unimplemented` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference between
unimplemented!
andtodo!
is that whiletodo!
conveys an intent of implementing the functionality later and the message is “not yet implemented”,unimplemented!
makes no such claims. Its message is “not implemented”.
By omission, this implies that unimplemented!
can be used to indicate intentionally/permanently unimplemented behaviour (eg. for target specific code), which implies that its use is not limited to debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good point. I'll remove that one later
These are `restriction` lints that look for patterns that can introduce panics. | ||
|
||
Usually panics are not something that one should want to avoid and most of the time panicking is perfectly valid | ||
(hence why these lints are allow-by-default), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(hence why these lints are allow-by-default), | |
(hence why these lints are in the `restriction` group), |
let regex = Regex::new( | ||
"(?s)\ | ||
(?<header><!-- lint-group-start: (?<name_start>[\\w-]+) -->)\ | ||
(?<lints>.*?)\ | ||
(?<footer><!-- lint-group-end: (?<name_end>[\\w-]+) -->)\ | ||
", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In clippy_dev::update_lints
there is a function called replace_region_in_{file,text}
that does the same thing as this, but without regex.
Why not implement this in clippy_dev
and use the facilities that are already there. It is probably a good extension for the update_lints
subcommand.
use itertools::Itertools; | ||
use regex::{Captures, Regex}; | ||
|
||
const GROUPS: &[(&str, &[&str])] = &[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you think about adding an optional "subgroup tag" to the define_clippy_lints
macro and then use that information to generate those groups, instead of listing them out here?
This might be better in the long run. WDYT?
This PR adds a new page to the book for more granular, "light" lint groups that are more informal than the real groups and can be easily added by anyone since it's "just" a page in the book.
I originally proposed this on Zulip a while ago: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.22Which.20lints.20should.20I.20enable.22.20page and people seemed to generally like the idea.
For the implementation, there are two parts involved:
The book page is partly generated and partly written by hand. Everything in between lint-group-start and lint-group-end is generated/checked by a test, everything else is manually written. There is also a comment on the page that explains this.
Having this extra test is probably not technically necessary and we could also just have a single
#[warn(..)]
list for every group, but this has the advantage that we can also provide the lint table code and do some extra checking, e.g. to make sure that all lints actually exist (preventing typos or lint names going stale if one gets renamed, ...).The actual code for generating it is less than 100 lines (excluding the data), so it doesn't seem like much extra complexity.
Another check that we could add (but doesn't exist right now) is that all listed lints actually live in that category (so that e.g. nursery-perf lints are removed when they get moved out of nursery)
changelog: none