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.'

Constants inherited from Cop

Cop::OPERATOR_METHODS

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_defs(node) ⇒ Object

TODO: Check if we're in a class/module



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

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

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