diff --git a/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb b/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb index 2600f5c969..daeb979bfd 100644 --- a/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb +++ b/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb @@ -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 diff --git a/spec/rubocop/cop/performance/redundant_equality_comparison_block_spec.rb b/spec/rubocop/cop/performance/redundant_equality_comparison_block_spec.rb index 999657ca9a..ef62797e09 100644 --- a/spec/rubocop/cop/performance/redundant_equality_comparison_block_spec.rb +++ b/spec/rubocop/cop/performance/redundant_equality_comparison_block_spec.rb @@ -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 }