-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Don't add Style/Alias offense for use of alias in eval_instance blocks #3004
Conversation
59fd4a9
to
c053edf
Compare
@@ -27,8 +27,11 @@ def on_send(node) | |||
def on_alias(node) | |||
# alias_method can't be used with global variables | |||
return if node.children.any?(&:gvar_type?) | |||
# alias_method can't be used in instance_eval blocks | |||
scope_type = scope_type(node) | |||
return if @must_use_alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once set, the value of @must_use_alias
remains and affects the inspection of the next alias
found in the same file. I think it's better if you add a third scope type called :instance_eval
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good catch, will fix 👍
c053edf
to
0db9ef9
Compare
👍 |
@magni- Squash the commit together and rebase on top of the current |
0db9ef9
to
5720ed5
Compare
@bbatsov done! |
Had to rebase this once more myself. The commit is merged now. |
Thanks! |
This fixes an issue with the
Style/Alias
cop.instance_eval
blocks are found to be dynamic scope, so Rubocop currently adds an offense when usingalias
instead ofalias_method
, but object instances do not respond toalias_method
.Before submitting a PR make sure the following are checked:
master
(if not - rebase it)and description in grammatically correct, complete sentences.