You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having a reduce loop and another loop inside of it, it's normal to next without an argument from the nested loop. It's only wrong to next without an argument from the reduce loop.
Actual behavior
Lint/NextWithoutAccumulator is reported.
Steps to reproduce the problem
Example code to reproduce:
result = [[1, 2, 3], [4, 5, 6]].inject([]) do |acc, elems|
elems.each_with_index do |elem, i|
next if i == 1
acc << elem
end
acc
end
puts result
gets us
Inspecting 1 file
W
Offenses:
repro.rb:3:5: W: Lint/NextWithoutAccumulator: Use next with an accumulator argument in a reduce.
next if i == 1
^^^^
1 file inspected, 1 offense detected
… enumeration
This cop would register an offense if a nested block contained a `next`
without an accumulator, e.g.:
```
[(1..3), (4..6)].reduce(0) do |acc, elems|
elems.each_with_index do |elem, i|
next if i == 1
acc << elem
end
acc
end
```
This fix addresses that, by checking if the direct block parent of any
offending `next` is indeed the block that we were inspecting.
… enumeration (rubocop#3313)
This cop would register an offense if a nested block contained a `next`
without an accumulator, e.g.:
```
[(1..3), (4..6)].reduce(0) do |acc, elems|
elems.each_with_index do |elem, i|
next if i == 1
acc << elem
end
acc
end
```
This fix addresses that, by checking if the direct block parent of any
offending `next` is indeed the block that we were inspecting.
Expected behavior
Having a
reduce
loop and another loop inside of it, it's normal tonext
without an argument from the nested loop. It's only wrong tonext
without an argument from thereduce
loop.Actual behavior
Lint/NextWithoutAccumulator
is reported.Steps to reproduce the problem
Example code to reproduce:
gets us
RuboCop version
The text was updated successfully, but these errors were encountered: