forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdl.rb
29 lines (26 loc) · 874 Bytes
/
mdl.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 `mdl` against any modified Markdown files
#
# @see https://github.com/mivok/markdownlint
class Mdl < Base
def run
result = execute(command, args: applicable_files)
output = result.stdout.chomp
return :pass if result.success?
return [:fail, result.stderr] unless result.stderr.empty?
# example message:
# [{"filename":"file1.md","line":1,"rule":"MD013","aliases":["line-length"],
# "description":"Line length"}]
json_messages = JSON.parse(output)
json_messages.map do |message|
Overcommit::Hook::Message.new(
:error,
message['filename'],
message['line'],
"#{message['filename']}:#{message['line']} #{message['rule']} #{message['description']}"
)
end
end
end
end