Skip to content
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 a case to lint_search_is_some to handle searching strings #6119

Merged
merged 9 commits into from
Nov 16, 2020

Conversation

rsulli55
Copy link
Contributor

@rsulli55 rsulli55 commented Oct 6, 2020

Fixes: #6010

This adds a lint which recommends using contains() instead of find() followed by is_some() on strings as suggested in #6010.

This was added as an additional case to

fn lint_search_is_some<'tcx>(

I would really appreciate any comments/suggestions for my code!

changelog: Added case to lint_search_is_some to handle searching strings

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 6, 2020
clippy_lints/src/find_is_some_on_strs.rs Outdated Show resolved Hide resolved
clippy_lints/src/find_is_some_on_strs.rs Outdated Show resolved Hide resolved
@pickfire
Copy link
Contributor

pickfire commented Oct 6, 2020

I followed the tutorial and called cargo dev new_lint to make this lint, but after looking more through the code base, I am not sure if this instead should be place in clippy_lints/src/methods/mod.rs. Specfically,

I think this should go into src/methods/mod.rs but I don't have much experience contributing to clippy myself, better wait for reviewer.

@flip1995
Copy link
Member

flip1995 commented Oct 9, 2020

Yeah, you're right, this should go into the methods module. IMO it doesn't even have to be a new lint, but a special case in the SEARCH_IS_SOME lint for &str and String. The

fn lint_search_is_some<'tcx>(
function seems to me to be the perfect place for this.

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 9, 2020
@rsulli55
Copy link
Contributor Author

rsulli55 commented Oct 10, 2020

Thanks for the comment! I will move it to lint_search_is_some()

Edit: So, I have done that but unfortunately, the commits are not so nice now (one of them is mostly just deleting files). Sorry about that, I am still pretty new to the PR workflow.

@rsulli55 rsulli55 changed the title WIP Add lint: find_is_some_on_strs Add lint: find_is_some_on_strs Oct 10, 2020
@rsulli55 rsulli55 changed the title Add lint: find_is_some_on_strs Add a case to lint_search_is_some to handle searching strings Oct 10, 2020
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I have done that but unfortunately, the commits are not so nice now (one of them is mostly just deleting files). Sorry about that, I am still pretty new to the PR workflow.

Don't worry about this for now, we can deal with that right before merging.


impl LGTM overall. Just a NIT and splitting up the tests left to do.

clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
tests/ui/methods.rs Outdated Show resolved Hide resolved
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Only a NIT left.

clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
@flip1995
Copy link
Member

@rsulli55 You have to update the reference files. After that, we can merge this.

@rsulli55
Copy link
Contributor Author

@flip1995 Thanks. I have done that, however I was having trouble rebasing my local branch on the upstream branch so I squashed some of my earlier commits. Is that okay? I have been holding off pushing my local branch because I wasn't sure if that would cause problems.

@bors
Copy link
Collaborator

bors commented Oct 30, 2020

☔ The latest upstream changes (presumably #6197) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@@ -3073,7 +3073,7 @@ fn lint_search_is_some<'tcx>(
then {
let msg = "called `is_some()` after calling `find()` \
on a string. This is more succinctly expressed by calling \
`contains()`";
`contains()`.";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flip1995 I added back in the period after contains() to match the other cases of search_is_some (they all end with a period). Let me know if you do not want that and I will remove it and re-run update-all-references.

By the way, thank you for you patience with me! Sorry if my questions are all basic things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh they're also in other places? Can you remove them there too, please? Rust error/hint/suggestion messages are always without punctuation at the end and start lower-case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also remove the second part of this message here completely and replace the "try this" below with use `contains()` instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flip1995 Ok, I think they should be correctly updated. I also cleaned up the other lints in search_is_some that suggested using any().

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more NITs left. This should be the last.

tests/ui/search_is_some.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
instead of `find()` follows by `is_some()` on strings

Update clippy_lints/src/find_is_some_on_strs.rs
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Update clippy_lints/src/methods/mod.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
`search_is_some.rs` and `search_is_some_fixable.rs`
rsulli55 and others added 6 commits November 10, 2020 23:18
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Philipp Krones <hello@philkrones.com>
@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Nov 16, 2020

📌 Commit 5c1c50e has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Nov 16, 2020

⌛ Testing commit 5c1c50e with merge ad4f829...

@bors
Copy link
Collaborator

bors commented Nov 16, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing ad4f829 to master...

@bors bors merged commit ad4f829 into rust-lang:master Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recommend contains() for find().is_some()
6 participants