Skip to content

Commit

Permalink
Merge pull request #360 from koic/fix_a_false_positive_for_performanc…
Browse files Browse the repository at this point in the history
…e_redundant_equality_comparison_block

[Fix #359] Fix a false positive for `Performance/RedundantEqualityComparisonBlock`
  • Loading branch information
koic committed May 20, 2023
2 parents 743226e + 3088b19 commit db59f48
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 db59f48

Please sign in to comment.