Sha256: c8c46401badaf894ca30bc8b5aee5a88ce2b14fbf58d506cb0f28206b2472b55

Contents?: true

Size: 1.12 KB

Versions: 192

Compression:

Stored size: 1.12 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.select do |key|
          key == department || key.start_with?("#{department}/")
        end
      end

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

Version data entries

192 entries across 185 versions & 17 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.67.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.66.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.66.0 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.65.1 lib/rubocop/config_obsoletion/extracted_cop.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.65.0 lib/rubocop/config_obsoletion/extracted_cop.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_obsoletion/extracted_cop.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_obsoletion/extracted_cop.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/config_obsoletion/extracted_cop.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.64.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.63.4 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.63.3 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.63.2 lib/rubocop/config_obsoletion/extracted_cop.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.63.1 lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.63.0 lib/rubocop/config_obsoletion/extracted_cop.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/config_obsoletion/extracted_cop.rb
rubocop-1.62.1 lib/rubocop/config_obsoletion/extracted_cop.rb