Sha256: d66dd633ea9ab538a5201e97ee1c01b856ecee78e2ef762da33a283b09f1ced1

Contents?: true

Size: 1.5 KB

Versions: 25

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # 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.
    #
    # @api private
    module EnforceSuperclass
      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, <<~PATTERN
          (class (const _ !:#{base::SUPERCLASS}) #{base::BASE_PATTERN} ...)
        PATTERN

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

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

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

Version data entries

25 entries across 23 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/enforce_superclass.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/enforce_superclass.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/enforce_superclass.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.33.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.32.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.31.2 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.31.1 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.31.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.30.1 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.30.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.29.1 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.29.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.28.2 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.28.1 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.28.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.27.0 lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.26.1 lib/rubocop/cop/mixin/enforce_superclass.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/enforce_superclass.rb
rubocop-1.26.0 lib/rubocop/cop/mixin/enforce_superclass.rb