Sha256: 36bd1cbe783682971713cdda90b01d29ec20c1084684aa268de2732a4bee542e

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

module SCSSLint
  class LinterError < StandardError; end
  class NoFilesError < StandardError; end

  # 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)
      raise NoFilesError, 'No SCSS files specified' if files.empty?

      files.each do |file|
        find_lints(file)
      end

      @linters.each do |linter|
        @lints += linter.lints
      end
    end

  private

    # @param file [String]
    def find_lints(file)
      engine = Engine.new(file)
      config = @config.preferred ? @config : Config.for_file(file)
      config ||= @config

      @linters.each do |linter|
        next unless config.linter_enabled?(linter)
        next if config.excluded_file_for_linter?(file, linter)

        begin
          linter.run(engine, config.linter_options(linter))
        rescue => error
          raise LinterError,
                "#{linter.class} raised unexpected error linting file #{file}: " <<
                "'#{error.message}'",
                error.backtrace
        end
      end
    rescue Sass::SyntaxError => ex
      @lints << Lint.new(ex.sass_filename, ex.sass_line, ex.to_s, :error)
    rescue FileEncodingError => ex
      @lints << Lint.new(file, 1, ex.to_s, :error)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scss-lint-0.22.0 lib/scss_lint/runner.rb
scss-lint-0.21.0 lib/scss_lint/runner.rb
scss-lint-0.20.3 lib/scss_lint/runner.rb
scss-lint-0.20.2 lib/scss_lint/runner.rb
scss-lint-0.20.1 lib/scss_lint/runner.rb
scss-lint-0.20.0 lib/scss_lint/runner.rb
scss-lint-0.19.0 lib/scss_lint/runner.rb