-
Notifications
You must be signed in to change notification settings - Fork 280
/
go_lint.rb
29 lines (25 loc) · 749 Bytes
/
go_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
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `golint` against any modified Golang files.
#
# @see https://github.com/golang/lint
class GoLint < Base
def run
output = ''
# golint doesn't accept multiple file arguments if
# they belong to different packages
applicable_files.each do |gofile|
result = execute(command, args: Array(gofile))
output += result.stdout + result.stderr
end
# Unfortunately the exit code is always 0
return :pass if output.empty?
# example message:
# path/to/file.go:1:1: Error message
extract_messages(
output.split("\n"),
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
)
end
end
end