Rubocop: alias_method no longer preffered

Created on 10 Feb 2016  路  6Comments  路  Source: rubocop-hq/rubocop

from v0.35.1, i believe the default enforced style for Style/Alias changed from alias_method to alias. at thats how it seems based on the yml file at line 13. I started getting the cop failing after upgrading to the latest.

Most helpful comment

.. Style/Alias .. doesn't allow me to discriminate between write-time or run-time aliasing. So I have to choose to either prefer alias or alias_method for _all_ scenarios which means I can't completely satisfy the style guide. Or am I missing something?

I had the same question. It looks like the cop is more sophisticated than that. It behaves differently in "dynamic" and "lexical" scopes. See alias_keyword_possible? below.

https://github.com/rubocop-hq/rubocop/blob/2f303909317f241336e52eedc340dc96bed71f39/lib/rubocop/cop/style/alias.rb#L34-L40

All 6 comments

Yes, the community style guide was recently updated and RuboCop's default config reflects the style guide.

hm interesting.... in that case, the aforementioned link to the line in enabled yml might want to me be re-worded as well. thanks for the quick response!

@bbatsov:

Yes, the community style guide was recently updated and RuboCop's default config reflects the style guide.

The Rubocop documentation for Style/Alias references this section of the styleguide which still recommends using alias_method vs alias. Why/where has the recommendation changed?

@floehopper That part is a recommendation for runtime aliasing. The relevant section for write-time is above it, here. 馃檪

@Drenmi Thanks for pointing that out. However, I'm still confused. As far as I can see there is only one alias-related rule in Rubocop, i.e. Style/Alias, which doesn't allow me to discriminate between write-time or run-time aliasing. So I have to choose to either prefer alias or alias_method for all scenarios which means I can't completely satisfy the style guide. Or am I missing something?

.. Style/Alias .. doesn't allow me to discriminate between write-time or run-time aliasing. So I have to choose to either prefer alias or alias_method for _all_ scenarios which means I can't completely satisfy the style guide. Or am I missing something?

I had the same question. It looks like the cop is more sophisticated than that. It behaves differently in "dynamic" and "lexical" scopes. See alias_keyword_possible? below.

https://github.com/rubocop-hq/rubocop/blob/2f303909317f241336e52eedc340dc96bed71f39/lib/rubocop/cop/style/alias.rb#L34-L40

Was this page helpful?
0 / 5 - 0 ratings