-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathherb_lint.rb
More file actions
27 lines (24 loc) · 802 Bytes
/
Copy pathherb_lint.rb
File metadata and controls
27 lines (24 loc) · 802 Bytes
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
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `herb-lint` against any modified ERB files.
#
# @see https://herb-tools.dev/projects/linter
class HerbLint < Base
def run
result = execute(command + ['--json'], args: applicable_files)
return :pass if result.success?
json_output = JSON.parse(result.stdout)
json_output['offenses'].map do |offense|
severity = offense['severity'] == 'error' ? :error : :warning
filename = offense['filename']
line = offense['location']['start']['line']
message = offense['message']
code = offense['code']
Overcommit::Hook::Message.new(
severity, filename, line,
"#{filename}:#{line} #{code} #{message}"
)
end
end
end
end