Module: RuboCop::Cop::EnforceSuperclass

Included in:
Rails::ApplicationController, Rails::ApplicationJob, Rails::ApplicationMailer, Rails::ApplicationRecord
Defined in:
lib/rubocop/cop/mixin/enforce_superclass.rb

Overview

Common functionality for enforcing a specific superclass.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.def_node_matcher :class_definition, "    (class (const _ !:\#{base::SUPERCLASS}) \#{base::BASE_PATTERN} ...)\n  PATTERN\n\n  base.def_node_matcher :class_new_definition, <<~PATTERN\n    [!^(casgn {nil? cbase} :\#{base::SUPERCLASS} ...)\n     !^^(casgn {nil? cbase} :\#{base::SUPERCLASS} (block ...))\n     (send (const {nil? cbase} :Class) :new \#{base::BASE_PATTERN})]\n  PATTERN\nend\n"

Instance Method Details

#on_class(node) ⇒ Object



24
25
26
27
28
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 24

def on_class(node)
  class_definition(node) do
    register_offense(node.children[1])
  end
end

#on_send(node) ⇒ Object



30
31
32
33
34
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 30

def on_send(node)
  class_new_definition(node) do
    register_offense(node.children.last)
  end
end