Skip to content

Commit

Permalink
[Fix #384] Mark unsafe for Rails/NegateInclude
Browse files Browse the repository at this point in the history
Fixes #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`)
  • Loading branch information
koic committed Nov 18, 2020
1 parent 4dae165 commit b024858
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [#371](https://github.com/rubocop-hq/rubocop-rails/pull/371): Fix an infinite loop error for `Rails/ActiveRecordCallbacksOrder` when callbacks have inline comments. ([@fatkodima][])
* [#364](https://github.com/rubocop-hq/rubocop-rails/pull/364): Fix a problem that `Rails/UniqueValidationWithoutIndex` doesn't work in classes defined with compact style. ([@sinsoku][])
* [#384](https://github.com/rubocop-hq/rubocop-rails/issues/384): Mark unsafe for `Rails/NegateInclude`. ([@koic][])

### Changes

Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ Rails/NegateInclude:
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
StyleGuide: 'https://rails.rubystyle.guide#exclude'
Enabled: 'pending'
Safe: false
VersionAdded: '2.7'
VersionChanged: '2.9'

Rails/NotNullColumn:
Description: 'Do not add a NOT NULL column without a default value.'
Expand Down
9 changes: 6 additions & 3 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2314,15 +2314,18 @@ match 'photos/:id', to: 'photos#show', via: :all
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Pending
| Yes
| Yes
| No
| Yes (Unsafe)
| 2.7
| -
| 2.9
|===

This cop enforces the use of `collection.exclude?(obj)`
over `!collection.include?(obj)`.

It is marked as unsafe by default because false positive will occur for
a receiver object that do not have `exclude?` method. (e.g. `IPAddr`)

=== Examples

[source,ruby]
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/rails/negate_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Rails
# This cop enforces the use of `collection.exclude?(obj)`
# over `!collection.include?(obj)`.
#
# It is marked as unsafe by default because false positive will occur for
# a receiver object that do not have `exclude?` method. (e.g. `IPAddr`)
#
# @example
# # bad
# !array.include?(2)
Expand Down

0 comments on commit b024858

Please sign in to comment.