-
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
New lint manual_split_once
#7565
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
51024fb
to
5a1f452
Compare
This already looks quite comprehensive! Great job! I think it'd be ready to merge and we can extend it with a later PR if you're OK with that. My suggestion is informed by
|
Just updated the docs as they mentioned something that currently isn't checked for. I see nothing wrong with merging it as is. It will probably be a week before I get to finishing the rest of the checks. |
11d28ee
to
8a9c512
Compare
Thank you! @bors r+ |
📌 Commit 8a9c512 has been approved by |
New lint `manual_split_once` This is a WIP because it still needs to recognize more patterns. Currently handles: ```rust s.splitn(2, ' ').next(); s.splitn(2, ' ').nth(0) s.splitn(2, ' ').nth(1); s.splitn(2, ' ').skip(0).next(); s.splitn(2, ' ').skip(1).next(); s.splitn(2, ' ').next_tuple(); // from itertools // as well as `unwrap()` and `?` forms ``` Still to do: ```rust let mut iter = s.splitn(2, ' '); (iter.next().unwrap(), iter.next()?) let mut iter = s.splitn(2, ' '); let key = iter.next().unwrap(); let value = iter.next()?; ``` Suggestions on other patterns to check for would be useful. I've done a search on github for uses of `splitn`. Still have yet to actually look through the results. There's also the question of whether the lint shouold trigger on all uses of `splitn` with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be. changelog: Add lint `manual_split_once`
💔 Test failed - checks-action_test |
It seems like #7566 which was merged shortly before this, again uses the |
8a9c512
to
aab3267
Compare
Let's try that again – @bors r+ |
📌 Commit aab3267 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This is a WIP because it still needs to recognize more patterns. Currently handles:
Still to do:
Suggestions on other patterns to check for would be useful. I've done a search on github for uses of
splitn
. Still have yet to actually look through the results.There's also the question of whether the lint shouold trigger on all uses of
splitn
with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be.changelog: Add lint
manual_split_once