Sha256: 6865b38f13fc5faff3de99945dd3dab05890ba20f5fd9eb3cc6858723138c3e9

Contents?: true

Size: 1.25 KB

Versions: 60

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This module encapsulates the ability to ignore certain methods when
    # parsing.
    # Cops that use `IgnoredMethods` can accept either strings or regexes to match
    # against.
    module IgnoredMethods
      # Configuration for IgnoredMethods. It is added to classes that include
      # the module so that configuration can be set using the `ignored_methods`
      # class macro.
      module Config
        attr_accessor :deprecated_key

        def ignored_methods(**config)
          self.deprecated_key = config[:deprecated_key]
        end
      end

      def self.included(base)
        base.extend(Config)
      end

      def ignored_method?(name)
        ignored_methods.any? do |value|
          case value
          when Regexp
            value.match? String(name)
          else
            value == String(name)
          end
        end
      end

      def ignored_methods
        keys = %w[IgnoredMethods]
        keys << deprecated_key if deprecated_key

        cop_config.slice(*keys).values.reduce(&:concat)
      end

      private

      def deprecated_key
        return unless self.class.respond_to?(:deprecated_key)

        self.class.deprecated_key&.to_s
      end
    end
  end
end

Version data entries

60 entries across 58 versions & 6 rubygems

Version Path
rubocop-1.16.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.16.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.15.0 lib/rubocop/cop/mixin/ignored_methods.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.14.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.13.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.12.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.12.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.11.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.10.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.9.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.9.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.8.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.8.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.7.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.6.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.6.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.5.2 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.5.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.5.0 lib/rubocop/cop/mixin/ignored_methods.rb