forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscss_lint.rb
28 lines (24 loc) · 947 Bytes
/
scss_lint.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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, 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 unless [1, 2].include?(result.status)
extract_messages(
result.stdout.split("\n"),
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+)/,
MESSAGE_TYPE_CATEGORIZER,
)
end
end
end