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

Suggestion for a new cop: Replace !foo.include?(bar) with foo.exclude?(bar) #17

Closed
ndbroadbent opened this issue Nov 15, 2018 · 2 comments · Fixed by #268
Closed

Suggestion for a new cop: Replace !foo.include?(bar) with foo.exclude?(bar) #17

ndbroadbent opened this issue Nov 15, 2018 · 2 comments · Fixed by #268
Labels
feature request Request for new functionality

Comments

@ndbroadbent
Copy link

ndbroadbent commented Nov 15, 2018

I recently remembered that ActiveSupport adds an exclude? method to Array and String. Before that, I was just using !foo.include?.

I would like to suggest a new cop that detects usage of !foo.include?(bar), and can auto-fix it to: foo.exclude?(bar).

Does that seem like a good idea to anyone else? I really like the exclude? method because it's easier to see the intention. (Similar to unless vs if.)

@ndbroadbent ndbroadbent changed the title Suggestion for a new cop: Replace !include? with exclude? Suggestion for a new cop: Replace !foo.include?(bar) with foo.exclude?(bar) Nov 15, 2018
@ndbroadbent
Copy link
Author

ndbroadbent commented Nov 15, 2018

I would be happy to submit a PR, but would like to ask for some help because I'm not familiar with the codebase. I think there's already a similar cop that converts if !foo into unless foo. Do you think it would be easy to copy that one and use it as an example? Or are there are some other cops that I should look at for inspiration?

EDIT: Oh I just found a much better example - !blank? vs. present?. I'll copy that one for include? vs. exclude?.

@andyw8
Copy link
Contributor

andyw8 commented Nov 16, 2018

@Drenmi Drenmi added the feature request Request for new functionality label Nov 16, 2018
@koic koic closed this as completed in #268 Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants