lib/scss_lint/config.rb in scss_lint-0.43.2 vs lib/scss_lint/config.rb in scss_lint-0.44.0

- old
+ new

@@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'yaml' module SCSSLint # Loads and manages application configuration. class Config - FILE_NAME = '.scss-lint.yml' + FILE_NAME = '.scss-lint.yml'.freeze DEFAULT_FILE = File.join(SCSS_LINT_HOME, 'config', 'default.yml') attr_reader :options, :warnings class << self @@ -69,10 +71,11 @@ options = convert_single_options_to_arrays(options) options = merge_wildcard_linter_options(options) options = ensure_exclude_paths_are_absolute(options, file) options = ensure_linter_exclude_paths_are_absolute(options, file) + ensure_severities_are_valid(options) options end # Convert any config options that accept a single value or an array to an # array form so that merging works. @@ -147,10 +150,31 @@ end options end + def ensure_severities_are_valid(options) + unless severity_is_valid?(options) + raise SCSSLint::Exceptions::InvalidConfiguration, + 'Global `severity` configuration option must be one of [' \ + "#{SEVERITIES.join(' | ')}]" + end + + options['linters'].each do |linter_name, linter_options| + next if severity_is_valid?(linter_options) + + raise SCSSLint::Exceptions::InvalidConfiguration, + "#{linter_name} `severity` configuration option must be one " \ + "of [#{SEVERITIES.join(' | ')}]" + end + end + + SEVERITIES = %w[error warning].freeze + def severity_is_valid?(options) + SEVERITIES.include?(options.fetch('severity', 'warning')) + end + def path_relative_to_config(relative_include_path, base_config_path) if relative_include_path.start_with?('/') relative_include_path else path = File.join(File.dirname(base_config_path), relative_include_path) @@ -193,11 +217,10 @@ # @param other [SCSSLint::Config] # @return [true,false] def ==(other) super || @options == other.options end - alias_method :eql?, :== # Extend this {Config} with another configuration. # # @return [SCSSLint::Config] def extend(config) @@ -244,10 +267,12 @@ linter_config['enabled'] = false end end def linter_options(linter) - @options['linters'].fetch(self.class.linter_name(linter), {}) + { 'severity' => @options['severity'] }.merge( + @options['linters'].fetch(self.class.linter_name(linter), {}) + ) end def excluded_file?(file_path) abs_path = File.expand_path(file_path)