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

Fix Style/CaseEquality when AllowOnConstant is true #7882

Merged
merged 1 commit into from Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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