Skip to content

Commit

Permalink
Merge pull request rubocop#12997 from Earlopain/error-for-unmodified-…
Browse files Browse the repository at this point in the history
…reduce-acc

Fix an error for `Lint/UnmodifiedReduceAccumulator` when the block is empty
  • Loading branch information
koic authored Jun 16, 2024
2 parents d123725 + 7b2e070 commit 047cbd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12997](https://github.com/rubocop/rubocop/pull/12997): Fix an error for `Lint/UnmodifiedReduceAccumulator` when the block is empty. ([@earlopain][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class UnmodifiedReduceAccumulator < Base
PATTERN

def on_block(node)
return unless node.body
return unless reduce_with_block?(node)
return unless node.argument_list.length >= 2

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/unmodified_reduce_accumulator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
RUBY
end

it "does not affect #{method} called with an empty block" do
expect_no_offenses(<<~RUBY)
values.#{method}(:+) { |result, value| }
RUBY
end

context "given a #{method} block" do
it 'does not register an offense when returning a literal' do
expect_no_offenses(<<~RUBY)
Expand Down

0 comments on commit 047cbd0

Please sign in to comment.