-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Correct the Cognitive Complexity lint's documentation #14915
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,25 @@ use rustc_span::def_id::LocalDefId; | |
|
||
declare_clippy_lint! { | ||
/// ### What it does | ||
/// Checks for methods with high cognitive complexity. | ||
/// We used to think it measured how hard a method is to understand. | ||
/// | ||
/// ### Why is this bad? | ||
/// Methods of high cognitive complexity tend to be hard to | ||
/// both read and maintain. Also LLVM will tend to optimize small methods better. | ||
/// Ideally, we would like to be able to measure how hard a function is | ||
/// to understand given its context (what we call its Cognitive Complexity). | ||
/// But that's not what this lint does. See "Known problems" | ||
/// | ||
/// ### Known problems | ||
/// Sometimes it's hard to find a way to reduce the | ||
/// complexity. | ||
/// The true Cognitive Complexity of a method is not something we can | ||
/// calculate using modern technology. This lint has been left in the | ||
/// `nursery` so as to not mislead users into using this lint as a | ||
/// measurement tool. | ||
/// | ||
/// ### Example | ||
/// You'll see it when you get the warning. | ||
/// For more detailed information, see [rust-clippy#3793](https://github.com/rust-lang/rust-clippy/issues/3793) | ||
/// | ||
/// ### Lints to consider instead of this | ||
/// | ||
/// * [`excessive_nesting`](https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting) | ||
/// * [`too_many_lines`](https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines) | ||
#[clippy::version = "1.35.0"] | ||
pub COGNITIVE_COMPLEXITY, | ||
nursery, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if it's clear we'll never fix this, this should be moved to I think this whole doc is written more like it would be for a deprecated lint (and written in a way I prefer, might I add), and there is already an internal lint that could probably get tripped up on this in the future. That's kinda my reasoning, though there are definitely still users of this lint (this wasn't always Suggesting the usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though, if anybody does ever work on it, in that coming decade, then this would be a bit of a problem, but maybe enough of a special case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see much maintenance burden here anyways. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@Centri3 I agree. I would rather see it deprecated (among other things, because even the concept of the lint itself is flawed). If I understood @flip1995 correctly, they'd rather it be kept in
❤️
Indeed. Phillip said so as well.
That's a very good point, I hadn't thought of that and it makes a lot of sense! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now added both suggestions. What's left is to hear Phillip's thoughts on deprecation :3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a problem with deprecating the lint:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on deprecating |
||
|
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.
Ignore if we deprecate this
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.
To be clear, I mean adding this alongside the new section