lib/scss_lint/config.rb in scss-lint-0.16.1 vs lib/scss_lint/config.rb in scss-lint-0.17.0
- old
+ new
@@ -60,20 +60,21 @@
# directives and merging the file's config with the files specified.
def load_options_hash_from_file(file)
file_contents = load_file_contents(file)
options =
- if file_contents.strip.empty?
- {}
+ if yaml = YAML.load(file_contents)
+ yaml.to_hash
else
- YAML.load(file_contents).to_hash
+ {}
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
# Convert any config options that accept a single value or an array to an
# array form so that merging works.
@@ -129,10 +130,23 @@
end
options
end
+ def ensure_linter_exclude_paths_are_absolute(options, original_file)
+ options = options.dup
+
+ options['linters'] ||= {}
+
+ options['linters'].keys.each do |linter_name|
+ options['linters'][linter_name] =
+ ensure_exclude_paths_are_absolute(options['linters'][linter_name], original_file)
+ end
+
+ options
+ end
+
# Ensure all excludes are absolute paths
def ensure_exclude_paths_are_absolute(options, original_file)
options = options.dup
if options['exclude']
@@ -221,9 +235,17 @@
def excluded_file?(file_path)
abs_path = File.expand_path(file_path)
@options.fetch('exclude', []).any? do |exclusion_glob|
+ File.fnmatch(exclusion_glob, abs_path)
+ end
+ end
+
+ def excluded_file_for_linter?(file_path, linter)
+ abs_path = File.expand_path(file_path)
+
+ linter_options(linter).fetch('exclude', []).any? do |exclusion_glob|
File.fnmatch(exclusion_glob, abs_path)
end
end
def exclude_file(file_path)