forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjscs.rb
25 lines (23 loc) · 764 Bytes
/
jscs.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
module Overcommit::Hook::PreCommit
# Runs `jscs` (JavaScript Code Style Checker) against any modified JavaScript
# files.
#
# @see http://jscs.info/
class Jscs < Base
def run
result = execute(command, args: applicable_files)
return :pass if result.success?
# Exit status 2 = Code style errors; everything else we don't know how to
# parse. https://github.com/jscs-dev/node-jscs/wiki/Exit-codes
unless result.status == 2
return :fail, result.stdout + result.stderr.chomp
end
# example message:
# path/to/file.js: line 7, col 0, ruleName: Error message
extract_messages(
result.stdout.split("\n"),
/^(?<file>(?:\w:)?[^:]+):[^\d]+(?<line>\d+)/,
)
end
end
end