Skip to content

Commit

Permalink
Fix error for Performance/RedundantEqualityComparisonBlock when blo…
Browse files Browse the repository at this point in the history
…ck is empty
  • Loading branch information
Earlopain committed May 25, 2024
1 parent 4752f8d commit 106202a
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 106202a

Please sign in to comment.