Module: RuboCop::Cop::EnforceSuperclass

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



7
8
9
10
11
12
13
14
15
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 7

def self.included(base)
  base.def_node_matcher :class_definition, <<~PATTERN
    (class (const _ !:#{base::SUPERCLASS}) #{base::BASE_PATTERN} ...)
  PATTERN

  base.def_node_matcher :class_new_definition, <<~PATTERN
    [!^(casgn nil? :#{base::SUPERCLASS} ...) (send (const nil? :Class) :new #{base::BASE_PATTERN})]
  PATTERN
end

Instance Method Details

#on_class(node) ⇒ Object



17
18
19
20
21
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 17

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

#on_send(node) ⇒ Object



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

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