Class: Rubocop::Cop::Style::ClassMethods

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

Overview

This cop checks for uses of the class/module name instead of self, when defining class/module methods.

Constant Summary collapse

MSG =
'Prefer self over class/module for class/module methods.'

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

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

Constructor Details

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

Instance Method Details

#on_defs(node) ⇒ Object

TODO - check if we're in a class/module



12
13
14
15
16
17
18
# File 'lib/rubocop/cop/style/class_methods.rb', line 12

def on_defs(node)
  definee, _name, _args, _body = *node

  if definee.type == :const
    add_offence(:convention, definee.loc.name, MSG)
  end
end