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/ShadowingOuterLocalVariable: a false positive case with if/eslif/else statement and block variable #10962

Closed
stefanoc opened this issue Aug 25, 2022 · 0 comments · Fixed by #10968
Labels

Comments

@stefanoc
Copy link

Expected behavior

No offense with Lint/ShadowingOuterLocalVariable cop

Actual behavior

 W: Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - item.
    items.each { |item| frobnicate(item) }
                  ^^^^

Steps to reproduce the problem

def do_something(items, what)
  if what == :first
    item = items[0]
    frobnicate(item)
  elsif what == :second
    item = items[1]
    frobnicate(item)
  else
    items.each { |item| frobnicate(item) }
  end
end

rubocop --only Lint/ShadowingOuterLocalVariable

Removing the elsif does not cause the warning to be emitted (see #10479)

RuboCop version

%% rubocop -V
1.35.1 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.2 x86_64-darwin21)
@koic koic added the bug label Aug 26, 2022
ydah added a commit to ydah/rubocop that referenced this issue Aug 26, 2022
…lVariable` when conditional with if/elsif/else branches

Fix: rubocop#10962
koic added a commit that referenced this issue Aug 27, 2022
[Fix #10962] Fix a false positive for `Lint/ShadowingOuterLocalVariable` when conditional with if/elsif/else branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants