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 doesn't recognize when local variable is in another context in case #1544

Closed
cheerfulstoic opened this issue Dec 30, 2014 · 2 comments

Comments

@cheerfulstoic
Copy link

I get this as an violation, but I don't think it should be:

      case columns.size
      when 0
        fail ArgumentError, 'No columns specified for Query#pluck'
      when 1
        column = columns[0]
        query.map { |row| row[column] }
      else
        query.map do |row|
          columns.map do |column|
            row[column]
          end
        end
      end

The violation is for the columns.map do |column| in the else, but the column variable is in the other branch of the case. Valid?

@jonas054
Copy link
Collaborator

jonas054 commented Jan 2, 2015

This is a duplicate of #1518 because this is another situation in which ruby and rubocop report the same problem.

/tmp$ ruby -wc shadow2.rb 
shadow2.rb:9: warning: shadowing outer local variable - column
Syntax OK
/tmp$ rubocop -f s shadow2.rb 
== shadow2.rb ==
W:  9: 21: Shadowing outer local variable - column.

1 file inspected, 1 offense detected

@jonas054 jonas054 closed this as completed Jan 2, 2015
@cheerfulstoic
Copy link
Author

Cool, thanks for rubocop!

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

No branches or pull requests

2 participants