class RuboCop::Cop::Lint::NextWithoutAccumulator
end
acc + i
next acc if i.odd?
result = (1..4).reduce(0) do |acc, i|
# good
end
acc + i
next if i.odd?
result = (1..4).reduce(0) do |acc, i|
# bad
@example
Don’t omit the accumulator when calling ‘next` in a `reduce` block.
def on_block(node)
def on_block(node) on_body_of_reduce(node) do |body| void_next = body.each_node(:next).find { |n| n.children.empty? } add_offense(void_next, :expression) if void_next end end