Sha256: 2ca8fd5c297dd2a6fcea7e218fa97153c84a50676591302442a171f172e00442

Contents?: true

Size: 934 Bytes

Versions: 2

Compression:

Stored size: 934 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Runs `scss-lint` against any modified SCSS files.
  #
  # @see https://github.com/brigade/scss-lint
  class ScssLint < Base
    MESSAGE_TYPE_CATEGORIZER = lambda do |type|
      type.include?('W') ? :warning : :error
    end

    def run
      result = execute(command + applicable_files)

      # Status code 81 indicates the applicable files were all filtered by
      # exclusions defined by the configuration. In this case, we're happy to
      # return success since there were technically no lints.
      return :pass if [0, 81].include?(result.status)

      # Any status that isn't indicating lint warnings or errors indicates failure
      return :fail, result.stdout unless [1, 2].include?(result.status)

      extract_messages(
        result.stdout.split("\n"),
        /^(?<file>[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+)/,
        MESSAGE_TYPE_CATEGORIZER,
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
overcommit-0.27.0 lib/overcommit/hook/pre_commit/scss_lint.rb
overcommit-0.26.0 lib/overcommit/hook/pre_commit/scss_lint.rb