-
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
Issue 8733: Suggest str.lines
when splitting at hard-coded newlines
#11987
Issue 8733: Suggest str.lines
when splitting at hard-coded newlines
#11987
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Jarcho (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Following the suggestions of @y21 in rust-lang#11987.
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.
This should also have a check for is_const_evaluatable
on the receiver for trim. If the string is a constant then at best using lines
makes no difference.
To answer some of your questions:
- No need to check for other ways of writing the constant. I would have even suggest not linting if the result came from a named constant anyways.
- The default snippet value only gets used with invalid spans, or when the source code is not available. i.e. It basically never happens.
- This would probably be better off as
pedantic
. Most of the results from GitHub are for code challenges where it doesn't matter anyways and may have been an intentional choice. Some of the results are for parsing unix config files where splitting on'\n'
is technically the correct choice."\r\n"
would be the correct choice for parsing Windows batch scripts.
Done.
Thanks!
Fixed. |
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.
Just one little note with the docs I missed last time. Otherwise this looks good.
☔ The latest upstream changes (presumably #12004) made this pull request unmergeable. Please resolve the merge conflicts. |
21fab26
to
a0ef520
Compare
Following the suggestions of @y21 in rust-lang#11987.
All good. Can you squash the commits down please. |
☔ The latest upstream changes (presumably #12054) made this pull request unmergeable. Please resolve the merge conflicts. |
Adds a new `splitting_strings_at_newlines` lint that suggests to use `str.lines` instead of splitting a trimmed string at hard-coded newlines.
a0ef520
to
fe35e08
Compare
@Jarcho: Rebased and squashed. |
Thank you. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #8733.
This is my first PR to Clippy and one of my first Rust PRs in general -- please feel free to nitpick, I'm thankful for any opportunity to learn! I'd be especially interested in feedback to the following points:
'\n'
,"\n"
, and"\r\n"
as arguments tosplit
enough, or should we do more (e.g. checking for constants that have those values if that is possible)?".."
forsnippet
a good choice? I copied it from other uses ofsnippet
in the code base, but I'm not entirely sure.suspicious
a good choice?MaybeIncorrect
a good choice? I used it because the return type oflines
is not exactly the same as that ofsplit
.