Skip to content

Commit

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

Fixes rubocop#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 e5e80c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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 e5e80c0

Please sign in to comment.