-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 new lint [needless_parens_on_range_literals
]
#8933
Add new lint [needless_parens_on_range_literals
]
#8933
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) soon. Please see the contribution instructions for more information. |
Not a review. Just some comments. ... AFAIK, Rust uses the term parenthesis for Here is an example where the suggestion fails because the
How does the lint handle macros? E.g. if the parens and literal are in a macro, does it recommend replacing the macro call with a literal? Maybe add some tests for that. |
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.
Welcome 🙂!
I'm not the reviewer, but I have some comments on top of @mikerite's.
/// ### Why is this bad? | ||
/// Having superflous braces makes the code less legible as the impose an | ||
/// overhead when reading. | ||
|
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.
It looks like you took the examples out of here and put them at the top of the file. They need to be within this macro for the docs to appear on the lint list.
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.
Implemented in 8185ecd
|
||
impl EarlyLintPass for NeedlessBracesOnRangeLiteral { | ||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { | ||
if let ExprKind::Range(Some(start), Some(end), _) = &e.kind { |
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.
What about the following cases:
let _ = ('a')..;
let _ = ..('z');
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.
Implemented in 496155d
if let Some(suggestion) = snippet_opt(cx, literal.span) { | ||
diag.span_suggestion(e.span, "try", suggestion, Applicability::MachineApplicable); | ||
} |
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 think this is better expressed with snippet_with_applicability
.
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.
Implemented in afe37e1
That's a great suggestion. Thanks, will add it |
Rewrote the check by |
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 for the PR, and welcome!
- The lint itself looks good, just some nits on spellings.
- Can you do a rebase instead of merge commits? We follow a no-merge policy
- We prefer plural form when naming lint. So the lint name would be
needless_parens_on_range_literals
. Can you also add the name to the changelog?
Also, huge thanks to @mikerite and @Serial-ATA for the suggestions and reviews!
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: dswij <[email protected]>
Thanks a lot. Did the following changes:
|
needless_braces_on_range_literal
]needless_parens_on_range_literals
]
Thanks for this! The lint looks great to me. @bors r+ |
📌 Commit 61d7dd2 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: Adds a new lint [
needless_parens_on_range_literals
] to warn on needless braces on literals in a range statementFor example, the lint would catch