Sha256: 9714485347fa9559538fa65617d28c7745f9273abff96057c5bb13e77acc8cf2

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This module encapsulates the ability to allow certain methods when
    # parsing. Even if the code is in offense, if it contains methods
    # that are allowed. This module is equivalent to the IgnoredMethods module,
    # which will be deprecated in RuboCop 2.0.
    module AllowedMethods
      private

      # @api public
      def allowed_method?(name)
        allowed_methods.include?(name.to_s)
      end

      # @deprecated Use allowed_method? instead
      def ignored_method?
        warn Rainbow(<<~WARNING).yellow, uplevel: 1
          `ignored_method?` is deprecated. Use `allowed_method?` instead.
        WARNING

        allowed_method?
      end

      # @api public
      def allowed_methods
        if cop_config_deprecated_values.any?(Regexp)
          cop_config_allowed_methods
        else
          cop_config_allowed_methods + cop_config_deprecated_values
        end
      end

      def cop_config_allowed_methods
        @cop_config_allowed_methods ||= Array(cop_config.fetch('AllowedMethods', []))
      end

      def cop_config_deprecated_values
        @cop_config_deprecated_values ||=
          Array(cop_config.fetch('IgnoredMethods', [])) +
          Array(cop_config.fetch('ExcludedMethods', []))
      end
    end
    # @deprecated IgnoredMethods class has been replaced with AllowedMethods.
    IgnoredMethods = AllowedMethods
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.69.2 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.69.1 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.69.0 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.68.0 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.67.0 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.66.1 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.66.0 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.65.1 lib/rubocop/cop/mixin/allowed_methods.rb
rubocop-1.65.0 lib/rubocop/cop/mixin/allowed_methods.rb