forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scalastyle.rb
31 lines (27 loc) · 815 Bytes
/
scalastyle.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
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `scalastyle` against any modified Scala files.
#
# @see http://www.scalastyle.org/
class Scalastyle < Base
MESSAGE_REGEX = /
^(?<type>error|warning)\s
file=(?<file>(?:\w:)?.+)\s
message=.+\s*
(line=(?<line>\d+))?
/x
def run
result = execute(command, args: applicable_files)
output = result.stdout.chomp + result.stderr.chomp
messages = output.split("\n").grep(MESSAGE_REGEX)
return [:fail, output] unless result.success? || messages.any?
# example message:
# error file=/path/to/file.scala message=Error message line=1 column=1
extract_messages(
messages,
MESSAGE_REGEX,
lambda { |type| type.to_sym }
)
end
end
end