forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dogma.rb
33 lines (29 loc) · 959 Bytes
/
dogma.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
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `dogma` against any modified ex files.
#
# @see https://github.com/lpil/dogma
class Dogma < Base
def run
result = execute command
return :pass if result.success?
messages = []
# example message:
# == web/channels/user_socket.ex ==
# 26: LineLength: Line length should not exceed 80 chars (was 83).
# 1: ModuleDoc: Module Sample.UserSocket is missing a @moduledoc.
output = result.stdout.chomp.match(/(==.+)/m)
if output
output.captures.first.split(/\n\n/).each do |error_group|
errors = error_group.split /\n/
file = errors.shift.gsub /[ =]/, ''
errors.each do |error|
line = error.split(': ').first
messages << Overcommit::Hook::Message.new(:error, file, line, "#{file}: #{error}")
end
end
end
messages
end
end
end