Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint/UnreachableLoop false positive when next appears in a branch #8607

Closed
vlad-pisanov opened this issue Aug 28, 2020 · 0 comments · Fixed by #8657
Closed

Lint/UnreachableLoop false positive when next appears in a branch #8607

vlad-pisanov opened this issue Aug 28, 2020 · 0 comments · Fixed by #8657

Comments

@vlad-pisanov
Copy link

In a loop where an if branch has both outcomes ending in break or rescue, but one branch has a next guard clause in it, Rubocop still complains about Lint/UnreachableLoop. Consider this:

[1, 2].each do |x|
  p x
  if x == 1
    next if x == 1
    break
  else
    break
  end
end

This runs twice.


Expected behavior

Should not complain about Lint/UnreachableLoop

Actual behavior

The loop runs twice, but Rubocop complains: "Lint/UnreachableLoop: This loop will have at most one iteration"

Steps to reproduce the problem

Run sample code

RuboCop version

0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.4.5 x86_64-darwin19)

Love all the work you're doing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant