-
-
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
[Fix #1460] Allow alias
in lexical class/module scope
#1461
[Fix #1460] Allow alias
in lexical class/module scope
#1461
Conversation
Fixed `Style/Alias` cop to allow the use of `alias` in lexical class and module scope, as the style guide does not forbid it.
The suggested changes don't make much sense - after all you can't actually use |
I'm not sure I understand your point. You certainly can use Object.class_exec { alias_method :id, :object_id }
# or
obj = Object.new
obj.singleton_class.class_exec { alias_method :id, :object_id } Maybe I'm misunderstanding how the AST parser works (very possible; I just sort of jumped into this) but I'm attempting to omit the enforcement of # OK
class Person
def first_name
names.first
end
alias given_name first_name
end ... but continue to disallow obj.singleton_class.class_exec { alias id object_id } Personally I wouldn't much care about the latter usage either but, then again, I'm generally confused about where we're asserting |
My point is that you can use alias println puts |
That's true and possibly indicates other problems with this cop, but how does it relate to my PR? I've made no changes to the way your example might be checked—evidenced by the existing specs that still pass. |
The problem is that the cop specs are actually flawed and your changes are actually affecting its current behaviour. The cop was intended specifically to disallow |
The comment left in rubocop/ruby-style-guide#377 by @meagar, and confirmed by you, states that the guide "doesn't forbid you from using I'm not trying to be confrontational or anything, I'd just like to bring this cop (and others) more in line with the rules. To me, the best thing about the style guide you've started (and why we're trying to adopt it at Wikimedia) is that it's community driven. However, when cops are introduced that either having no correlation to the guide or are incongruent with the discussion/consensus therein, it seems to undermine the participatory nature of it all. |
I'm not saying that I'm against the proposed change; I'm saying you should consider its implications for the existing users, which will likely be surprised that the behaviour of the cop was changed without any way for them to use the old behaviour. I'm also saying that the current implementation (before your patch) is flawed, therefore we can't rely on the tests. Perhaps it'd actually be best to make this cop look for just We should also update the style guide, of course, as the current state of the rule is less than ideal.
Yeah, guess it might feel this way sometimes for which I truly apologise. Unfortunately I don't have that much time on my hands to review everything carefully and from time to time cops that are out of sync with the guide get introduced/enabled. I'm always willing to work towards fixing this. |
P.S. We can also make this cop configurable, of course. By default it will enforce the new style, but there'll be an option to enforce the current style as well. |
I see where you're coming from. It appears we're both trying to achieve "least surprise"—me from the standpoint of a new RuboCop user, and you from the standpoint of a current one.
Hey, no worries; that's completely understandable. I wonder if a policy on discussion before implementation would be helpful in mitigating divergence. In other words, defer requests for new cops or PRs that change cop behavior to the style guide repo for discussion first—at least before anything gets merged. The style guide is in a pretty good state overall (easily the best Ruby style guide out there), and it might benefit from "slowing its roll" on new rules anyhow. :)
Cool! Let's continue the discussion in rubocop/ruby-style-guide#383, get the style guide in order, then I'll come back to this and refactor accordingly.
I totally didn't get that. Sorry, my brain is fried today. |
OK, now we can move forward with this. As I said earlier the cop has to have two supported styles - the current and the new. They can be named something like |
@marxarelli Now that the guide is updated you can continue with the changes here. |
@marxarelli ping :-) |
Closing due to lack of activity. |
Fixed
Style/Alias
cop to allow the use ofalias
in lexical class andmodule scope, as the style guide does not forbid it.