Class: Rubocop::Cop::Style::Alias

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/style/alias.rb

Overview

The purpose of the this cop is advise the use of alias_method over the alias keyword whenever possible.

Constant Summary collapse

MSG =
'Use alias_method instead of alias.'

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_alias(node) ⇒ Object

TODO: Make this check context aware - alias_method is not available outside of classes/modules.



13
14
15
16
17
18
19
20
21
22
# File 'lib/rubocop/cop/style/alias.rb', line 13

def on_alias(node)
  # alias_method can't be used with global variables
  new, old = *node

  return if new.type == :gvar && old.type == :gvar

  add_offence(:convention,
              node.loc.keyword,
              MSG)
end