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

Rails/NegateInclude is not safe for auto correction #384

Closed
adamcooke opened this issue Nov 16, 2020 · 2 comments · Fixed by #385
Closed

Rails/NegateInclude is not safe for auto correction #384

adamcooke opened this issue Nov 16, 2020 · 2 comments · Fixed by #385
Labels
bug Something isn't working

Comments

@adamcooke
Copy link

We cannot assume that everything that implements include? also implements exclude?. While Rails does add this to some things, it doesn't add them to everything and making this assumption is dangerous.

For example, IPAddr (in stdlib) has an include? method but does not have an exclude?.

Expected behaviour

Inserting !something.include?(x) should not correct to something.exclude?(x).

Actual behavior

It was corrected.

RuboCop version

$ [bundle exec] rubocop -V
1.3.0
koic added a commit to koic/rubocop-rails that referenced this issue Nov 18, 2020
@koic koic added the bug Something isn't working label Nov 18, 2020
koic added a commit to koic/rubocop-rails that referenced this issue Nov 18, 2020
Fixes rubocop#384

This PR marks unsafe for `Rails/NegateInclude` because false positive
will occurs for a receiver object that do not have `exclude?` method.
(e.g. `IPAddr`)
koic added a commit to koic/rubocop-rails that referenced this issue Nov 18, 2020
Fixes rubocop#384

This PR marks unsafe for `Rails/NegateInclude` because false positive
will occurs for a receiver object that do not have `exclude?` method.
(e.g. `IPAddr`)
koic added a commit to koic/rubocop-rails that referenced this issue Nov 18, 2020
Fixes rubocop#384

This PR marks unsafe for `Rails/NegateInclude` because false positive
will occur for a receiver object that do not have `exclude?` method.
(e.g. `IPAddr`)
@koic koic closed this as completed in #385 Nov 18, 2020
koic added a commit that referenced this issue Nov 18, 2020
@adamcooke
Copy link
Author

Thank you!

@koic
Copy link
Member

koic commented Nov 18, 2020

@adamcooke You are welcome. Thank you for the feedback!

koic added a commit to koic/rubocop-rails that referenced this issue Nov 20, 2020
Fixes rubocop#384

This PR marks unsafe for `Rails/NegateInclude` because false positive
will occur for a receiver object that do not have `exclude?` method.
(e.g. `IPAddr`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants