lib/scss_lint/config.rb in scss-lint-0.30.0 vs lib/scss_lint/config.rb in scss-lint-0.31.0
- old
+ new
@@ -1,12 +1,9 @@
require 'pathname'
require 'yaml'
module SCSSLint
- # Raised when the configuration file is invalid for some reason.
- class InvalidConfiguration < StandardError; end
-
# Loads and manages application configuration.
class Config
FILE_NAME = '.scss-lint.yml'
DEFAULT_FILE = File.join(SCSS_LINT_HOME, 'config', 'default.yml')
@@ -70,11 +67,12 @@
yaml.to_hash
else
{}
end
rescue => ex
- raise InvalidConfiguration, "Invalid configuration: #{ex.message}"
+ 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)
@@ -120,23 +118,28 @@
options = options.dup
options.fetch('linters', {}).keys.each do |class_name|
next unless class_name.include?('*')
- class_name_regex = /#{class_name.gsub('*', '[^:]+')}/
-
wildcard_options = options['linters'].delete(class_name)
+ apply_options_to_matching_linters(class_name, options, wildcard_options)
+ end
- LinterRegistry.linters.each do |linter_class|
- name = linter_name(linter_class)
- next unless name.match(class_name_regex)
+ options
+ end
- old_options = options['linters'].fetch(name, {})
- options['linters'][name] = smart_merge(old_options, wildcard_options)
- end
+ def apply_options_to_matching_linters(class_name_glob, current_options, linter_options)
+ linter_names_matching_glob(class_name_glob).each do |linter_name|
+ old_options = current_options['linters'].fetch(linter_name, {})
+ current_options['linters'][linter_name] = smart_merge(old_options, linter_options)
end
+ end
- options
+ def linter_names_matching_glob(class_name_glob)
+ class_name_regex = /#{class_name_glob.gsub('*', '[^:]+')}/
+
+ LinterRegistry.linters.map { |linter_class| linter_name(linter_class) }
+ .select { |linter_name| linter_name.match(class_name_regex) }
end
def ensure_linter_exclude_paths_are_absolute(options, original_file)
options = options.dup