Skip to content

Commit

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

Fixes rubocop#214.

This PR fixes a false positive for `Performance/RedundantEqualityComparisonBlock`
when using multiple block arguments.
  • Loading branch information
koic committed Mar 1, 2021
1 parent c8bea56 commit 8cef567
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#207](https://github.com/rubocop/rubocop-performance/issues/207): Fix a false positive for `Performance/RedundantEqualityComparisonBlock` when using multiple block arguments. ([@koic][])

## 1.10.0 (2021-03-01)

### New features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RedundantEqualityComparisonBlock < Base
COMPARISON_METHODS = %i[== === is_a? kind_of?].freeze

def on_block(node)
return unless TARGET_METHODS.include?(node.method_name)
return unless TARGET_METHODS.include?(node.method_name) && node.arguments.one?

block_argument = node.arguments.first
block_body = node.body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
RUBY
end

it 'does not register and corrects an offense when using multiple block arguments' do
expect_no_offenses(<<~RUBY)
items.all? { |key, _value| key == other }
RUBY
end

it 'does not register and corrects an offense when using block argument is not used as it is' do
expect_no_offenses(<<~RUBY)
items.all? { |item| item.do_something == other }
Expand Down

1 comment on commit 8cef567

@davidenglishmusic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Please sign in to comment.