lib/scss_lint/config.rb in scss_lint-0.39.0 vs lib/scss_lint/config.rb in scss_lint-0.40.0

- old
+ new

@@ -16,15 +16,22 @@ # Loads a configuration from a file, merging it with the default # configuration. def load(file, options = {}) config_options = load_options_hash_from_file(file) + config = new(config_options) + + # Need to call this before merging with the default configuration so + # that plugins can override the default configuration while still being + # overridden by the repo's configuration. + config.load_plugins + if options.fetch(:merge_with_default, true) - config_options = smart_merge(default_options_hash, config_options) + config = default.extend(config) end - Config.new(config_options) + config end # Returns the location of the user-wide scss-lint configuration. # # This needs to be a method instead of a constant so that we can change @@ -176,10 +183,36 @@ @warnings = [] validate_linters end + def [](key) + @options[key] + end + + # Compares this configuration with another. + # + # @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) + @options = self.class.send(:smart_merge, @options, config.options) + @warnings += config.warnings + self + end + + def load_plugins + load_plugins_and_merge_config.tap { ensure_plugins_have_default_options } + end + def enabled_linters LinterRegistry.extract_linters_from(@options['linters'].keys).select do |linter| linter_options(linter)['enabled'] end end @@ -252,8 +285,27 @@ Linter.const_get(name) rescue NameError @warnings << "Linter #{name} does not exist; ignoring" end end + end + + def load_plugins_and_merge_config + SCSSLint::Plugins.new(self).load.each do |plugin| + # Have the plugin options be overrideable by the local configuration + @options = self.class.send(:smart_merge, plugin.config.options, @options) + end + end + + def ensure_plugins_have_default_options + LinterRegistry.linters.each do |linter| + if linter_options(linter).nil? + @options['linters'].merge!(default_plugin_options(linter)) + end + end + end + + def default_plugin_options(linter) + { self.class.linter_name(linter) => { 'enabled' => true } } end end end