Sha256: 0644d7078d9afc849f7a15ca636e2d356d4f51af989f12ef8a2e0f4cee8ff6ee

Contents?: true

Size: 1.07 KB

Versions: 42

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module RuboCop
  class ConfigObsoletion
    # Encapsulation of a ConfigObsoletion rule for splitting a cop's
    # functionality into multiple new cops.
    # @api private
    class ExtractedCop < CopRule
      attr_reader :gem, :department

      def initialize(config, old_name, gem)
        super(config, old_name)
        @department, * = old_name.rpartition('/')
        @gem = gem
      end

      def violated?
        return false if feature_loaded?

        affected_cops.any?
      end

      def rule_message
        msg = '%<name>s been extracted to the `%<gem>s` gem.'
        format(msg,
               name: affected_cops.size > 1 ? "`#{department}` cops have" : "`#{old_name}` has",
               gem: gem)
      end

      private

      def affected_cops
        return old_name unless old_name.end_with?('*')

        # Handle whole departments (expressed as `Department/*`)
        config.keys.grep(Regexp.new("^#{department}"))
      end

      def feature_loaded?
        config.loaded_features.include?(gem)
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/config_obsoletion/extracted_cop.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.26.1 lib/rubocop/config_obsoletion/extracted_cop.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.26.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.25.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.25.0 lib/rubocop/config_obsoletion/extracted_cop.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.24.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.24.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.23.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.22.3 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.22.2 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.22.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.22.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.21.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.20.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.19.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.19.0 lib/rubocop/config_obsoletion/extracted_cop.rb