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/CaseLikeIf not properly handling overriden equality methods #8624

Merged
merged 1 commit into from Aug 31, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,7 @@
* [#8321](https://github.com/rubocop-hq/rubocop/issues/8321): Enable auto-correction for `Layout/{Def}EndAlignment`, `Lint/EmptyEnsure`. ([@marcandre][])
* [#8583](https://github.com/rubocop-hq/rubocop/issues/8583): Fix `Style/RedundantRegexpEscape` false positive for line continuations. ([@owst][])
* [#8593](https://github.com/rubocop-hq/rubocop/issues/8593): Fix `Style/RedundantRegexpCharacterClass` false positive for interpolated multi-line expressions. ([@owst][])
* [#8624](https://github.com/rubocop-hq/rubocop/pull/8624): Fix an error with the `Style/CaseLikeIf` cop where it does not properly handle overridden equality methods with no arguments. ([@Skipants][])

### Changes

Expand Down Expand Up @@ -4821,3 +4822,4 @@
[@chocolateboy]: https://github.com/chocolateboy
[@Lykos]: https://github.com/Lykos
[@jaimerave]: https://github.com/jaimerave
[@Skipants]: https://github.com/Skipants
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/case_like_if.rb
Expand Up @@ -116,7 +116,7 @@ def find_target_in_send_node(node)
def find_target_in_equality_node(node)
argument = node.arguments.first
receiver = node.receiver
return unless receiver
return unless argument && receiver

if argument.literal? || const_reference?(argument)
receiver
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/case_like_if_spec.rb
Expand Up @@ -336,4 +336,12 @@
foo if x == 1
RUBY
end

it 'does not register an offense when an object overrides `equal?` with no arity' do
expect_no_offenses(<<~RUBY)
if x.equal?
elsif y
end
RUBY
end
end