Class: Overcommit::Hook::PreCommit::ScssLint

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/scss_lint.rb

Overview

Runs ‘scss-lint` against any modified SCSS files.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/overcommit/hook/pre_commit/scss_lint.rb', line 8

def run
  result = execute(command, args: 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 + result.stderr) unless [1, 2].include?(result.status)

  begin
    collect_lint_messages(JSON.parse(result.stdout))
  rescue JSON::ParserError => e
    [:fail, "Unable to parse JSON returned by SCSS-Lint: #{e.message}\n" \
                  "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"]
  end
end