Skip to content

Commit

Permalink
Merge pull request #8624 from Skipants/master
Browse files Browse the repository at this point in the history
Fix `Style/CaseLikeIf` not properly handling overriden equality methods
  • Loading branch information
koic committed Aug 31, 2020
2 parents 6cab599 + f877e02 commit f69a7a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit f69a7a8

Please sign in to comment.