Sha256: 5f43eb4dd7451e11387de8f03028d501e6bbbb6a3ba462ebb7738e4cf69f48e0

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

module SCSSLint
  # Finds and aggregates all lints found by running the registered linters
  # against a set of SCSS files.
  class Runner
    attr_reader :lints

    # @param config [Config]
    def initialize(config)
      @config  = config
      @lints   = []
      @linters = LinterRegistry.linters.map(&:new)
    end

    # @param files [Array]
    def run(files)
      files.each do |file|
        find_lints(file)
      end
    end

  private

    # @param file [String]
    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

    # For stubbing in tests.
    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
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
scss_lint-0.40.1 lib/scss_lint/runner.rb
scss_lint-0.40.0 lib/scss_lint/runner.rb
scss_lint-0.39.0 lib/scss_lint/runner.rb
scss_lint-0.38.0 lib/scss_lint/runner.rb
scss-lint-0.38.0 lib/scss_lint/runner.rb
scss-lint-bliss-1.0.0 lib/scss_lint/runner.rb