forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffee_lint.rb
35 lines (30 loc) · 844 Bytes
/
coffee_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
29
30
31
32
33
34
35
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `coffeelint` against any modified CoffeeScript files.
#
# @see http://www.coffeelint.org/
class CoffeeLint < Base
MESSAGE_REGEX = /
^(?<file>.+)
,(?<line>\d*),\d*
,(?<type>\w+)
,(?<msg>.+)$
/x
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('w') ? :warning : :error
end
def run
result = execute(command, args: applicable_files)
parse_messages(result.stdout)
end
private
def parse_messages(output)
output.scan(MESSAGE_REGEX).map do |file, line, type, msg|
line = line.to_i
type = MESSAGE_TYPE_CATEGORIZER.call(type)
text = "#{file}:#{line}:#{type} #{msg}"
Overcommit::Hook::Message.new(type, file, line, text)
end
end
end
end