Skip to content

Commit ca1c242

Browse files
committed
Fix an error for Rails/NegateInclude when there is no receiver
1 parent 73fe04a commit ca1c242

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#920](https://github.com/rubocop/rubocop-rails/pull/920): Fix an error for `Rails/NegateInclude` when there is no receiver. ([@fatkodima][])

lib/rubocop/cop/rails/negate_include.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NegateInclude < Base
2626
RESTRICT_ON_SEND = %i[!].freeze
2727

2828
def_node_matcher :negate_include_call?, <<~PATTERN
29-
(send (send $_ :include? $_) :!)
29+
(send (send $!nil? :include? $_) :!)
3030
PATTERN
3131

3232
def on_send(node)

spec/rubocop/cop/rails/negate_include_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
RUBY
1313
end
1414

15+
it 'does not register an offense when using `!include?` without receiver' do
16+
expect_no_offenses(<<~RUBY)
17+
!include?(2)
18+
RUBY
19+
end
20+
1521
it 'does not register an offense when using `include?` or `exclude?`' do
1622
expect_no_offenses(<<~RUBY)
1723
array.include?(2)

0 commit comments

Comments
 (0)