Sha256: 6d37a40256c0ffbb0a5f545eb2a6c1bcd8247c3a2e9a3ddf59ca89e5d363a11b

Contents?: true

Size: 1.95 KB

Versions: 236

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module RuboCop
  # Handles caching of configurations and association of inspected
  # ruby files to configurations.
  class ConfigStore
    attr_reader :validated
    alias validated? validated

    def initialize
      # @options_config stores a config that is specified in the command line.
      # This takes precedence over configs located in any directories
      @options_config = nil

      # @path_cache maps directories to configuration paths. We search
      # for .rubocop.yml only if we haven't already found it for the
      # given directory.
      @path_cache = {}

      # @object_cache maps configuration file paths to
      # configuration objects so we only need to load them once.
      @object_cache = {}

      # By default the config is validated before it can be used.
      @validated = true
    end

    def options_config=(options_config)
      loaded_config = ConfigLoader.load_file(options_config)
      @options_config = ConfigLoader.merge_with_default(loaded_config, options_config)
    end

    def force_default_config!
      @options_config = ConfigLoader.default_configuration
    end

    def unvalidated
      @validated = false
      self
    end

    def for_file(file)
      for_dir(File.dirname(file))
    end

    def for_pwd
      for_dir(Dir.pwd)
    end

    # If type (file/dir) is known beforehand,
    # prefer using #for_file or #for_dir for improved performance
    def for(file_or_dir)
      dir = if File.directory?(file_or_dir)
              file_or_dir
            else
              File.dirname(file_or_dir)
            end
      for_dir(dir)
    end

    def for_dir(dir)
      return @options_config if @options_config

      @path_cache[dir] ||= ConfigLoader.configuration_file_for(dir)
      path = @path_cache[dir]
      @object_cache[path] ||= begin
        print "For #{dir}: " if ConfigLoader.debug?
        ConfigLoader.configuration_from_file(path, check: validated?)
      end
    end
  end
end

Version data entries

236 entries across 227 versions & 23 rubygems

Version Path
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.87 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.86 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.85 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/config_store.rb