Skip to content

Commit

Permalink
Merge pull request #452 from Earlopain/fix-error-for-redundant-equali…
Browse files Browse the repository at this point in the history
…ty-check

Fix error for `Performance/RedundantEqualityComparisonBlock` when block is empty
  • Loading branch information
koic authored May 26, 2024
2 parents 4752f8d + 106202a commit cec9f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#452](https://github.com/rubocop/rubocop-performance/pull/452): Fix an error for `Performance/RedundantEqualityComparisonBlock` when the block is empty. ([@earlopain][])
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def on_block(node)
return unless one_block_argument?(node.arguments)

block_argument = node.first_argument
block_body = node.body
return unless (block_body = node.body)
return unless use_equality_comparison_block?(block_body)
return if same_block_argument_and_is_a_argument?(block_body, block_argument)
return unless (new_argument = new_argument(block_argument, block_body))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,16 @@
items.any? { |item| do_something[0..item] == item }
RUBY
end

it 'does not register an offense when the block is empty' do
expect_no_offenses(<<~RUBY)
items.any? { |item| }
RUBY
end

it 'does not register an offense when the block takes no argument' do
expect_no_offenses(<<~RUBY)
items.any? { }
RUBY
end
end

0 comments on commit cec9f54

Please sign in to comment.