lib/scss_lint/runner.rb in scss-lint-0.12.1 vs lib/scss_lint/runner.rb in scss-lint-0.13.0

- old
+ new

@@ -1,53 +1,43 @@ module SCSSLint class LinterError < StandardError; end class NoFilesError < StandardError; end - class NoLintersError < StandardError; end # Finds and aggregates all lints found by running the registered linters # against a set of SCSS files. class Runner - attr_reader :linters, :lints + attr_reader :lints - def initialize(options = {}) + def initialize(config) + @config = config @lints = [] - - included_linters = LinterRegistry. - extract_linters_from(options.fetch(:included_linters, [])) - - included_linters = LinterRegistry.linters if included_linters.empty? - - excluded_linters = LinterRegistry. - extract_linters_from(options.fetch(:excluded_linters, [])) - - @linters = (included_linters - excluded_linters).map(&:new) + @linters = LinterRegistry.linters.map(&:new) end - def run(files = []) + def run(files) raise NoFilesError, 'No SCSS files specified' if files.empty? - raise NoLintersError, 'No linters specified' if linters.empty? files.each do |file| find_lints(file) end - linters.each do |linter| + @linters.each do |linter| @lints += linter.lints end end - def lints? - lints.any? - end - private def find_lints(file) engine = Engine.new(file) + config = @config.preferred ? @config : Config.for_file(file) + config ||= @config - linters.each do |linter| + @linters.each do |linter| + next unless config.linter_enabled?(linter) + begin - linter.run(engine) + linter.run(engine, config.linter_options(linter)) rescue => error raise LinterError, "#{linter.class} raised unexpected error linting file #{file}: " << "'#{error.message}'", error.backtrace