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
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/ignored_methods.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/ignored_methods.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/ignored_methods.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.32.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.31.2 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.31.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.31.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.30.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.30.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.29.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.29.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.28.2 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.28.1 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.28.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.27.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.26.1 lib/rubocop/cop/mixin/ignored_methods.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.26.0 lib/rubocop/cop/mixin/ignored_methods.rb
rubocop-1.25.1 lib/rubocop/cop/mixin/ignored_methods.rb