Skip to content
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 @@
* [#498](https://github.com/rubocop/rubocop-performance/pull/498): Fix `Performance/Count` cop error on empty selector block. ([@viralpraxis][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/performance/count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def autocorrect(corrector, node, selector_node, selector)
end

def eligible_node?(node)
!(node.parent && node.parent.block_type?)
return false if node.parent&.block_type?

node.receiver.call_type? || node.receiver.body
end

def source_starting_at(node)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/performance/count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,12 @@ def count(&block)
RUBY
end
end

context 'with `reject` with empty block body' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
array.reject {}.size
RUBY
end
end
end