Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

y21
Copy link
Member

@y21 y21 commented Oct 5, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Oct 5, 2024

r? @flip1995

rustbot has assigned @flip1995.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 5, 2024
@@ -38,6 +38,7 @@ serde_json = "1.0.122"
toml = "0.7.3"
walkdir = "2.3"
filetime = "0.2.9"
indoc = "1.0"
Copy link
Member Author

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),
Copy link
Member Author

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

@y21 y21 changed the title More granular lint groups book page Add a "more granular lint groups" page to the book Oct 5, 2024
or has remaining debugging artifacts.

<!-- lint-group-start: debugging -->
Lints: `dbg_macro`, `todo`, `unimplemented`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per unimplemented!'s docs:

The difference between unimplemented! and todo! is that while todo! 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.

Copy link
Member Author

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(hence why these lints are allow-by-default),
(hence why these lints are in the `restriction` group),

Comment on lines +61 to +67
let regex = Regex::new(
"(?s)\
(?<header><!-- lint-group-start: (?<name_start>[\\w-]+) -->)\
(?<lints>.*?)\
(?<footer><!-- lint-group-end: (?<name_end>[\\w-]+) -->)\
",
)
Copy link
Member

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])] = &[
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants