-
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
Most commonly ignored lints #5418
Comments
This is very interesting, thank you! I'm wondering how skewed the data might be since the regex does not differentiate between disabling a lint on crate level #[allow(clippy::useless_format)]
let _ = format!("{}", "a"); We might also want to look the same way at |
I had a look at the top 10 items and looked at suppressing warnings on single items
|
This makes a lot of sense to me. I still think we should deprecate the Cognitive Complexity lint, if not moving it to "Pedantic". I was the last one to touch it, and tried re-implementing it only to find out while researching it, the reality of our current understanding of Cognitive Complexity: we're not good enough yet at analyzing code for understandability. To see the discussion that was had on the topic, you can go to the issue itself and start here: #3793 (comment) Thank you for this investigation, @dtolnay ❤️ |
Yeah, we should move cognitive complexity to nursery I think. |
Given that new_without_default is enabled more at the file level than on the item level, that also seems like a strong indicator that people don't value it much. |
👍 anecdotally I haven't found new_without_default to be valuable. It's a good observation that new_without_default is one of the two in the top ten for which globally disabling is more common than one-off exceptions, the other being unreadable_literal which we know is controversial. I agree that we can take this to mean people don't find it valuable. |
I'm not very surprised to see both cognitive_complexity and too_many_arguments right next too each other at the top. In my experience those two tend to interact badly. If you have a problem which just involves a lot of complex logic with a lot of edge cases, it can become hard to factor it out into multiple functions that do not just trigger too_many_arguments itself. And wrapping those args in a struct to reduce the too_many_arguments warning then just causes more clutter in the original function making the whole thing more complex than it already was (unless you can reuse that struct multiple times but complex logic and borrowing rules tend to inhibit that). |
I did something similar in November. I counted each level (forbid/deny/warn/allow) of all lints, counting each lint only once per crate across crates.io. You can filter on |
I think seeing a difference between global and local disables is useful here. Clippy is meant to be used with a liberal sprinkling of allow, both to pick your personal style, and to deal with cases where you actually need to write code the way clippy doesn't want you to. If a lot of folks are globally disabling style lints that's a good indicator that Clippy style has diverged from the community. Local disables are harder to grok, because to some extent they can be a signal. I agree cognitive complexity should be off by default, but it's a good example here: a legit way of using it is to get an early warning when your functions get complicated, and turn it off whenever you feel like they have to be that way. It's still valuable as a signal in this case! |
For We also probably should document that this lint can by definition not look at the actual variant distribution in your program execution, so it may be that the smallest variant is only used in a very small percentage of cases, in which case boxing the largest variant would likely not bring much benefit. |
Oh, good point. You reminded me of Huffman encoding, where you pick the most probable variants and encode them with less bits, so that in average you get the best performance. In many cases, the large enum variant might be a result of applying the same idea to the particular usage of that enum. That seems very interesting. Also smart. |
I did disable complexity ones many times myself. Usually there's just no way to fix these. Some complexity is just essential, and shuffling it around only obscures it. Though I usually disable it on case-by-case basis, not globally. I don't really mind it on it's own. It's a a decent annotation that "yes, the authors realize that this is complexgly and have reasons to keep it". |
Oh, another good example of this is lints that want you to make a choice, where one of the choice is to In general I'd be wary of viewing |
Downgrade unreadable_literal to pedantic As motivated by rust-lang#5418. This is the top most commonly suppressed Clippy style lint, which indicates that the community has decided they don't share Clippy's opinion on the best style of this. I've left the lint in as pedantic, though it could be that "restriction" would be better -- I can see this lint being useful as an opt-in restriction in some codebases. changelog: Remove unreadable_literal from default set of enabled lints
Downgrade new_ret_no_self to pedantic As motivated by rust-lang#5418. This is the second most widely suppressed Clippy style lint, and [this grep.app search](https://grep.app/search?q=%5C%5Ballow%5C%28.%2Aclippy%3A%3Anew_ret_no_self%5Cb®exp=true&case=true&filter[lang][0]=Rust) shows a large number of diverse reasonable signatures for a `new` method. changelog: Remove new_ret_no_self from default set of enabled lints
Downgrade unreadable_literal to pedantic As motivated by rust-lang#5418. This is the top most commonly suppressed Clippy style lint, which indicates that the community has decided they don't share Clippy's opinion on the best style of this. I've left the lint in as pedantic, though it could be that "restriction" would be better -- I can see this lint being useful as an opt-in restriction in some codebases. changelog: Remove unreadable_literal from default set of enabled lints
Downgrade new_ret_no_self to pedantic As motivated by rust-lang#5418. This is the second most widely suppressed Clippy style lint, and [this grep.app search](https://grep.app/search?q=%5C%5Ballow%5C%28.%2Aclippy%3A%3Anew_ret_no_self%5Cb®exp=true&case=true&filter[lang][0]=Rust) shows a large number of diverse reasonable signatures for a `new` method. changelog: Remove new_ret_no_self from default set of enabled lints
Move cognitive_complexity to nursery As discussed in #5418 (comment); Clippy's current understanding of cognitive complexity is not good enough yet at analyzing code for understandability to have this lint be enabled by default. changelog: Remove cognitive_complexity from default set of enabled lints
Please recheck the PR thread on new_ret_no_self: I don't think that one should have been merged. |
compare with the second largest instead of the smallest variant This should make the lint less noisy for now. See [my comment](#5418 (comment)) to issue #5418. --- changelog: none
compare with the second largest instead of the smallest variant This should make the lint less noisy for now. See [my comment](#5418 (comment)) to issue #5418. --- changelog: none
What if the second largest one is as large as the largest but the third largest deviates a lot? For example, 8000, 8000, 64, 64, 64? Shouldn't it look into standard deviation or variance in this sort of case? |
I also thought about that, but for now decided against it as a) this would make the lint much more complex and b) as I wrote in the |
Regarding |
Which is really strange, because the lint has the following code:
|
@llogiq Maybe that code was added later... or does the lint not ignore |
It doesn't lint private functions. Also |
* as of the error reworking commit, tasks sometimes didn't erase lines when it should have. most specifically at the beginning of tasks being executed, and all tasks completing. this is now fixed, as the task_inidcator ignores logs that happened before it started, and properly counts how many lines it added, that it needs to erase. * we've reworked all of the codebase, so almost all clippy warnings that were previously ignored, are no longer ignored, and code has been rewritten so the lint step passes. * There are some "clippy::too_many_arguments" being ignored, I intend to fix these, but these require more of a deft hand, and so I don't want to rush it. reworking may also not be needed once I try it. (This is currently the most ignored clippy warning according too: rust-lang/rust-clippy#5418) and reasoning I agree with is there. * There is one: `#[allow(unused)]` for pipeline descriptions. This is true, it is unused right now, but I want to keep it in the schema because I do want to render the pipeline in list one day. I just haven't found quite a way to do it yet, but i added it in because I know I want to do it (and I don't want to remove it). * this has also resulted in a giant split up of docker executor, so it is no longer all in one gigantic file. This really _really_ needed to be done, so I'm glad I finally did it.
* as of the error reworking commit, tasks sometimes didn't erase lines when it should have. most specifically at the beginning of tasks being executed, and all tasks completing. this is now fixed, as the task_inidcator ignores logs that happened before it started, and properly counts how many lines it added, that it needs to erase. * we've reworked all of the codebase, so almost all clippy warnings that were previously ignored, are no longer ignored, and code has been rewritten so the lint step passes. * There are some "clippy::too_many_arguments" being ignored, I intend to fix these, but these require more of a deft hand, and so I don't want to rush it. reworking may also not be needed once I try it. (This is currently the most ignored clippy warning according too: rust-lang/rust-clippy#5418) and reasoning I agree with is there. * There is one: `#[allow(unused)]` for pipeline descriptions. This is true, it is unused right now, but I want to keep it in the schema because I do want to render the pipeline in list one day. I just haven't found quite a way to do it yet, but i added it in because I know I want to do it (and I don't want to remove it). * this has also resulted in a giant split up of docker executor, so it is no longer all in one gigantic file. This really _really_ needed to be done, so I'm glad I finally did it.
I have an HTTP client trait/object where |
Closing in favor of #7666, which reproduces a similar table using all published crates on crates.io as the data source, rather than repos indexed by grep.app. The code is available in https://github.com/dtolnay/noisy-clippy. |
I collected some data from https://grep.app on which Clippy lints are needing to be suppressed most commonly in the wild. This is based on number of results for this regex:
which is an approximation but useful. Example query
Clippy's most severe flaw in my experience has been low-signal lints that are enabled by default, aren't worth resolving and commonly need to be suppressed. Hopefully this gives some data to support deleting or downgrading many of those lints to pedantic opt-in lints.
In the table below, I would recommend paying attention to the style and perf lints. On style, highly suppressed style lints indicate that the community has consciously decided that Clippy's opinion on style is wrong. On perf, highly suppressed lints indicate that the community does not consider it valuable to make their code more obtuse for the sake of questionable alleged performance. I think it would be wise to delete or downgrade many of these.
Here is the distribution by lint of how many times lints are suppressed. As expected, most lints are rarely suppressed, but there are a dozen or so lints that are very commonly suppressed.
And here are the top most commonly ignored lints. I'll cross off lints as I delete or downgrade them.
432cognitive_complexitycomplexity201unreadable_literalstyle193new_ret_no_selfstyle178trivially_copy_pass_by_refperf141needless_pass_by_valuestyle38let_unit_valuestyle36option_optioncomplexity31implicit_hasherstyle28identity_conversioncomplexity25useless_let_if_seqstyle22match_wild_err_armstyle20match_boolstyleThe text was updated successfully, but these errors were encountered: