-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Lint more cases in collapsible_if
#14231
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
Conversation
b8d9f37 to
a94f321
Compare
|
I think I'll add a configuration option to merge @rustbot author |
a94f321 to
bc44671
Compare
|
Done, with the @rustbot review |
419a0a2 to
24c2681
Compare
6d030ab to
f065214
Compare
collapsible_if, without suggestionscollapsible_if
f065214 to
14aa958
Compare
|
Rebased |
14aa958 to
affd2a7
Compare
|
Rebased |
|
r? clippy |
affd2a7 to
43b8c88
Compare
|
Rebased after rustup |
flip1995
left a comment
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.
LGTM overall, just a few NITs. After a full review, I noticed that the comment is kept, so defaulting the config to true is more reasonable. I would still be a bit more conservative and set it to false for this PR, in order to get it merged more quickly and then revisit it in a later PR.
clippy_config/src/conf.rs
Outdated
| /// Whether collapsible `if` chains are linted if they contain comments inside the parts | ||
| /// that would be collapsed. | ||
| #[lints(collapsible_if)] | ||
| lint_commented_code: bool = true, |
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.
| lint_commented_code: bool = true, | |
| lint_commented_code: bool = false, |
If there is a comment between the 2 if stmts, it is a strong indication that the separation is intentional and for readability.
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.
Done
clippy_lints/src/collapsible_if.rs
Outdated
| } | ||
|
|
||
| /// If the expression is a `||`, suggest parentheses around it. | ||
| fn par_around_or(expr: &ast::Expr) -> Vec<(Span, String)> { |
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.
NIT: parens is a more common abbreviation of parentheses.
| fn par_around_or(expr: &ast::Expr) -> Vec<(Span, String)> { | |
| fn parens_around_or(expr: &ast::Expr) -> Vec<(Span, String)> { |
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.
Done. I think I played with Sugg::maybe_par() first, and kept this abbreviation. I'll add checking if proposing to rename this to Sugg::maybe_paren() to my TODO list.
Replace the use of `Sugg::ast()` which prevented combining `if` together when they contained comments by span manipulation. A new configuration option `lint_commented_code`, which is `true` by default, opts out from this behavior.
43b8c88 to
9c39dc5
Compare
I've set the default to |
|
Interesting: the lintcheck test fails, because in the |
9c39dc5 to
8238160
Compare
flip1995
left a comment
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.
Thanks!
|
r? @flip1995 |
This PR enables the new ability to collapse `if` statements containing comments (without losing them) in Clippy sources, excluding tests and lintcheck, where the default behaviour (no collapsing in presence of comments) is preserved. To be applied after #14231. When it is applied, #14455 will be marked as ready for review, then #14228 afterwards. changelog: none r? ghost
Replace the use of
Sugg::ast()which prevented combiningiftogether when they contained comments by span manipulation.A new configuration option
lint_commented_code, which istrueby default, allows opting out from this behavior.If reviewed on GitHub, the second commit of this PR is best looked at side by side, with whitespace differences turned off.
changelog: [
collapsible_if]: lint more cases