forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlint.rb
32 lines (28 loc) · 748 Bytes
/
hlint.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
module Overcommit::Hook::PreCommit
# Runs `hlint` against any modified Haskell files.
#
# @see https://github.com/ndmitchell/hlint
class Hlint < Base
MESSAGE_REGEX = /
^(?<file>(?:\w:)?[^:]+)
:(?<line>\d+)
:\d+
:\s*(?<type>\w+)
/x
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('W') ? :warning : :error
end
def run
result = execute(command, args: applicable_files)
return :pass if result.success?
raw_messages = result.stdout.split("\n").grep(MESSAGE_REGEX)
# example message:
# path/to/file.hs:1:0: Error: message
extract_messages(
raw_messages,
MESSAGE_REGEX,
MESSAGE_TYPE_CATEGORIZER
)
end
end
end