Class: Rubocop::Cop::Style::Alias
- 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.'
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#on_alias(node) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubocop/cop/style/alias.rb', line 23 def on_alias(node) return if ignored_node?(node) # alias_method can't be used with global variables new, old = *node return if new.type == :gvar && old.type == :gvar convention(node, :keyword) end |
#on_block(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rubocop/cop/style/alias.rb', line 11 def on_block(node) method, _args, body = *node _receiver, method_name = *method # using alias is the only option in certain scenarios # in such scenarios we don't want to report an offence if method_name == :instance_exec on_node(:alias, body) { |n| ignore_node(n) } end end |