Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error for Performance/RedundantEqualityComparisonBlock when block is empty #452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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? { }
Earlopain marked this conversation as resolved.
Show resolved Hide resolved
RUBY
end
end