class SCSSLint::Runner

Finds and aggregates all lints found by running the registered linters against a set of SCSS files.

Attributes

lints[R]

Public Class Methods

new(config) click to toggle source

@param config [Config]

# File lib/scss_lint/runner.rb, line 8
def initialize(config)
  @config  = config
  @lints   = []
  @linters = LinterRegistry.linters.map(&:new)
end

Public Instance Methods

run(files) click to toggle source

@param files [Array]

# File lib/scss_lint/runner.rb, line 15
def run(files)
  files.each do |file|
    find_lints(file)
  end
end

Private Instance Methods

find_lints(file) click to toggle source

@param file [String]

# File lib/scss_lint/runner.rb, line 24
def find_lints(file)
  engine = Engine.new(file: file)

  @linters.each do |linter|
    begin
      run_linter(linter, engine, file)
    rescue => error
      raise SCSSLint::Exceptions::LinterError,
            "#{linter.class} raised unexpected error linting file #{file}: " \
            "'#{error.message}'",
            error.backtrace
    end
  end
rescue Sass::SyntaxError => ex
  @lints << Lint.new(nil, ex.sass_filename, Location.new(ex.sass_line),
                     "Syntax Error: #{ex}", :error)
rescue FileEncodingError => ex
  @lints << Lint.new(nil, file, Location.new, ex.to_s, :error)
end
run_linter(linter, engine, file) click to toggle source

For stubbing in tests.

# File lib/scss_lint/runner.rb, line 45
def run_linter(linter, engine, file)
  return unless @config.linter_enabled?(linter)
  return if @config.excluded_file_for_linter?(file, linter)
  @lints += linter.run(engine, @config.linter_options(linter))
end