lib/scss_lint/runner.rb in scss-lint-0.11.1 vs lib/scss_lint/runner.rb in scss-lint-0.12.0
- old
+ new
@@ -1,9 +1,12 @@
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
def initialize(options = {})
@lints = []
@@ -18,32 +21,40 @@
@linters = (included_linters - excluded_linters).map(&:new)
end
def run(files = [])
- raise NoFilesError.new('No SCSS files specified') if files.empty?
- raise NoLintersError.new('No linters specified') if linters.empty?
+ 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|
@lints += linter.lints
end
end
+ def lints?
+ lints.any?
+ end
+
+ private
+
def find_lints(file)
engine = Engine.new(file)
linters.each do |linter|
- linter.run(engine)
+ begin
+ linter.run(engine)
+ rescue => error
+ raise LinterError,
+ "#{linter.class} raised unexpected error: '#{error.message}'",
+ error.backtrace
+ end
end
rescue Sass::SyntaxError => ex
@lints << Lint.new(ex.sass_filename, ex.sass_line, ex.to_s, :error)
- end
-
- def lints?
- lints.any?
end
end
end