lib/scss_lint/config.rb in scss-lint-0.33.0 vs lib/scss_lint/config.rb in scss-lint-0.34.0
- old
+ new
@@ -1,15 +1,13 @@
-require 'pathname'
require 'yaml'
module SCSSLint
# Loads and manages application configuration.
class Config
FILE_NAME = '.scss-lint.yml'
DEFAULT_FILE = File.join(SCSS_LINT_HOME, 'config', 'default.yml')
- attr_accessor :preferred # If this config should be preferred over others
attr_reader :options, :warnings
class << self
def default
load(DEFAULT_FILE, merge_with_default: false)
@@ -25,35 +23,17 @@
end
Config.new(config_options)
end
- # Loads the configuration for a given file.
- def for_file(file_path)
- directory = File.dirname(File.expand_path(file_path))
- @dir_to_config ||= {}
- @dir_to_config[directory] ||=
- begin
- config_file = possible_config_files(directory).find(&:file?)
- Config.load(config_file.to_s) if config_file
- end
- end
-
def linter_name(linter)
linter = linter.is_a?(Class) ? linter : linter.class
linter.name.split('::')[2..-1].join('::')
end
private
- def possible_config_files(directory)
- files = Pathname.new(directory)
- .enum_for(:ascend)
- .map { |path| path + FILE_NAME }
- files << Pathname.new(FILE_NAME)
- end
-
def default_options_hash
@default_options_hash ||= load_options_hash_from_file(DEFAULT_FILE)
end
# Recursively load config files, fetching files specified by `include`
@@ -72,11 +52,10 @@
raise SCSSLint::Exceptions::InvalidConfiguration,
"Invalid configuration: #{ex.message}"
end
options = convert_single_options_to_arrays(options)
- options = extend_inherited_configs(options, file)
options = merge_wildcard_linter_options(options)
options = ensure_exclude_paths_are_absolute(options, file)
options = ensure_linter_exclude_paths_are_absolute(options, file)
options
end
@@ -86,35 +65,17 @@
def convert_single_options_to_arrays(options)
options = options.dup
if options['exclude']
# Ensure exclude is an array, since we allow user to specify a single
- # string. We do this before merging with the config loaded via
- # inherit_from since this allows us to merge the excludes from that,
- # rather than overwriting them.
+ # string.
options['exclude'] = [options['exclude']].flatten
end
options
end
- # Loads and extends a list of inherited options with the given options.
- def extend_inherited_configs(options, original_file)
- return options unless options['inherit_from']
- options = options.dup
-
- includes = [options.delete('inherit_from')].flatten.map do |include_file|
- load_options_hash_from_file(path_relative_to_config(include_file, original_file))
- end
-
- merged_includes = includes[1..-1].inject(includes.first) do |merged, include_file|
- smart_merge(merged, include_file)
- end
-
- smart_merge(merged_includes, options)
- end
-
# Merge options from wildcard linters into individual linter configs
def merge_wildcard_linter_options(options)
options = options.dup
options.fetch('linters', {}).keys.each do |class_name|
@@ -208,14 +169,9 @@
@options = options
@warnings = []
validate_linters
end
-
- def ==(other)
- super || @options == other.options
- end
- alias_method :eql?, :==
def enabled_linters
LinterRegistry.extract_linters_from(@options['linters'].keys).select do |linter|
linter_options(linter)['enabled']
end