forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsl.rb
28 lines (24 loc) · 788 Bytes
/
jsl.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
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `jsl` against any modified JavaScript files.
#
# @see http://www.javascriptlint.com/
class Jsl < Base
MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/.freeze
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.match?(/warning/) ? :warning : :error
end
def run
file_flags = applicable_files.map { |file| ['-process', file] }
result = execute(command + file_flags.flatten)
return :pass if result.success?
# example message:
# path/to/file.js(1): lint warning: Error message
extract_messages(
result.stdout.split("\n").grep(MESSAGE_REGEX),
MESSAGE_REGEX,
MESSAGE_TYPE_CATEGORIZER
)
end
end
end