Class: RuboCop::Cop::Cobra::Inheritance

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/cobra/inheritance.rb

Constant Summary collapse

PROTECTED_GLOBAL_CONSTANTS =
%w[
  ApplicationController
  ApplicationRecord
  ApiController
].freeze
MSG =
"Do not directly inherit from a global %<class>s. " \
"Instead, inherit from your component's modularized " \
"%<class>s, such as MyComponent::%<class>s."

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/rubocop/cop/cobra/inheritance.rb', line 17

def on_class(node)
  inheritance_constant = node.node_parts[1]
  inheritance_class = inheritance_constant&.source
  return unless PROTECTED_GLOBAL_CONSTANTS.include?(inheritance_class)

  add_offense(inheritance_constant,
              message: format(MSG, class: inheritance_class))
end