Skip to content

Commit

Permalink
Fix Style/CaseEquality when AllowOnConstant is true
Browse files Browse the repository at this point in the history
When the method receiver is implicit it was failing with a NoMethodError
in `nil` error.
  • Loading branch information
rafaelfranca committed Apr 16, 2020
1 parent eb3d358 commit 09d46fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#7882](https://github.com/rubocop-hq/rubocop/pull/7882): Fix `Style/CaseEquality` when `AllowOnConstant` is `true` and the method receiver is implicit. ([@rafaelfranca][])

## 0.82.0 (2020-04-16)

### New features
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/case_equality.rb
Expand Up @@ -42,7 +42,7 @@ def on_send(node)

def const?(node)
if cop_config.fetch('AllowOnConstant', false)
!node.const_type?
!node&.const_type?
else
true
end
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/case_equality_spec.rb
Expand Up @@ -21,6 +21,12 @@
)
end

it 'does not fail when the receiver is implicit' do
expect_no_offenses(<<~RUBY)
puts "No offense"
RUBY
end

it 'does not register an offense for === when the receiver is a constant' do
expect_no_offenses(<<~RUBY)
Array === var
Expand Down

0 comments on commit 09d46fa

Please sign in to comment.