Skip to content

Commit cec9f54

Browse files
authored
Merge pull request #452 from Earlopain/fix-error-for-redundant-equality-check
Fix error for `Performance/RedundantEqualityComparisonBlock` when block is empty
2 parents 4752f8d + 106202a commit cec9f54

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#452](https://github.com/rubocop/rubocop-performance/pull/452): Fix an error for `Performance/RedundantEqualityComparisonBlock` when the block is empty. ([@earlopain][])

lib/rubocop/cop/performance/redundant_equality_comparison_block.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def on_block(node)
6464
return unless one_block_argument?(node.arguments)
6565

6666
block_argument = node.first_argument
67-
block_body = node.body
67+
return unless (block_body = node.body)
6868
return unless use_equality_comparison_block?(block_body)
6969
return if same_block_argument_and_is_a_argument?(block_body, block_argument)
7070
return unless (new_argument = new_argument(block_argument, block_body))

spec/rubocop/cop/performance/redundant_equality_comparison_block_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,16 @@
181181
items.any? { |item| do_something[0..item] == item }
182182
RUBY
183183
end
184+
185+
it 'does not register an offense when the block is empty' do
186+
expect_no_offenses(<<~RUBY)
187+
items.any? { |item| }
188+
RUBY
189+
end
190+
191+
it 'does not register an offense when the block takes no argument' do
192+
expect_no_offenses(<<~RUBY)
193+
items.any? { }
194+
RUBY
195+
end
184196
end

0 commit comments

Comments
 (0)