Module: RuboCop::Cop::EnforceSuperclass Private

Defined in:
lib/rubocop/cop/mixin/enforce_superclass.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Common functionality for enforcing a specific superclass.

IMPORTANT: RuboCop core depended on this module when it supported Rails department. Rails department has been extracted to RuboCop Rails gem. This module is deprecated and will be removed by RuboCop 2.0. It will not be updated to ‘RuboCop::Cop::Base` v1 API to maintain compatibility with existing RuboCop Rails 2.8 or lower.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 15

def self.included(base)
  warn Rainbow(
    '`RuboCop::Cop::EnforceSuperclass` is deprecated and will be removed in RuboCop 2.0. ' \
    'Please upgrade to RuboCop Rails 2.9 or newer to continue.'
  ).yellow

  # @!method class_definition(node)
  base.def_node_matcher :class_definition, "    (class (const _ !:\#{base::SUPERCLASS}) \#{base::BASE_PATTERN} ...)\n  PATTERN\n\n  # @!method class_new_definition(node)\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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 34

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

#on_send(node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/rubocop/cop/mixin/enforce_superclass.rb', line 38

def on_send(node)
  class_new_definition(node) { add_offense(node.children.last) }
end