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

ShadowingOuterLocalVariable and UnusedLocalVariable triggered by Regexp with named captures #332

Closed
badal opened this issue Jul 3, 2013 · 6 comments · Fixed by #334
Closed
Assignees

Comments

@badal
Copy link

badal commented Jul 3, 2013

2 errors occurred:
An error occurred while ShadowingOuterLocalVariable cop was inspecting
...
An error occurred while UnusedLocalVariable cop was inspecting ...

0.9.0 (using Parser 2.0.0.beta9, running on ruby 1.9.3 i386-mingw32)

Both errors are triggered by the following line :

   if /(?<token>\w+)(?<setter>=?)/ =~ name.to_s && token_names.include?(token)
@ghost ghost assigned yujinakayama Jul 3, 2013
@yujinakayama
Copy link
Collaborator

I'm looking at this, but it probably takes some time to handle this because the named capture variables don't appear in the AST.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 3, 2013

@yujinakayama Pretty sure @whitequark implemented support for them recently.

@badal
Copy link
Author

badal commented Jul 3, 2013

@yujinakayama No problem : this occurs in a legacy project I am cleaning, and I do not think I'll keep those named captures...

@yujinakayama
Copy link
Collaborator

@bbatsov I cannot see any node for it in both AST and the document.

$ ruby-parse -V
ruby-parse based on parser version 2.0.0.beta10
$ ruby-parse -e '/(?<match>bar)/ =~ baz'
(match-with-lvasgn
  (regexp
    (str "(?<match>bar)")
    (regopt))
  (send nil :baz))

@whitequark
Copy link

@yujinakayama Eh? You're looking at this node: match-with-lvasgn. If you want just the variable names, parse the inner (str) with Regexp.new--that's how Parser extracts them. There will be only one child str node.

@yujinakayama
Copy link
Collaborator

@whitequark Oh I didn't even know Regexp#named_captures. Thanks.

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

Successfully merging a pull request may close this issue.

4 participants