Skip to content

Commit

Permalink
[Fix #359] Fix a false positive for `Performance/RedundantEqualityCom…
Browse files Browse the repository at this point in the history
…parisonBlock`

Fixes #359.

This PR fixes a false positive for `Performance/RedundantEqualityComparisonBlock`
when the block variable is used on both sides of `==`.
  • Loading branch information
koic committed May 17, 2023
1 parent 4e7233d commit 3088b19
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#359](https://github.com/rubocop/rubocop-performance/issues/359): Fix a false positive for `Performance/RedundantEqualityComparisonBlock` when the block variable is used on both sides of `==`. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def same_block_argument_and_is_a_argument?(block_body, block_argument)
elsif IS_A_METHODS.include?(block_body.method_name)
block_argument.source == block_body.first_argument.source
else
false
block_body.receiver.source == block_body.first_argument.receiver&.source
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
RUBY
end

it 'does not register an offense when the block variable is used on both sides of `==`' do
expect_no_offenses(<<~RUBY)
items.all? { |item| item == item.do_something }
RUBY
end

it 'does not register an offense when using not target methods with `===` comparison block' do
expect_no_offenses(<<~RUBY)
items.do_something { |item| item == other }
Expand Down

0 comments on commit 3088b19

Please sign in to comment.