Skip to content

Commit

Permalink
Merge 2a17fad into 192c84b
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmil committed Apr 19, 2021
2 parents 192c84b + 2a17fad commit 8fa77a5
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/overcommit/hook/pre_commit/yaml_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@ module Overcommit::Hook::PreCommit
#
# @see https://github.com/adrienverge/yamllint
class YamlLint < Base
MESSAGE_REGEX = /
^(?<file>.+)
:(?<line>\d+)
:(?<col>\d+)
:\s\[(?<type>\w+)\]
\s(?<msg>.+)$
/x

def run
result = execute(command, args: applicable_files)
parse_messages(result.stdout)
end

private

def parse_messages(output)
repo_dir = Pathname.new(Overcommit::Utils.git_dir).parent.to_s

output.scan(MESSAGE_REGEX).map do |file, line, col, type, msg|
line = line.to_i
type = type.to_sym
# Obtain the path relative to the root of the repository
# for nicer output:
relpath = file.dup
relpath.slice!("#{repo_dir}/")

if result.success?
:pass
elsif result.stdout.include?('error')
[:fail, result.stdout]
else
[:warn, result.stdout]
text = "#{relpath}:#{line}:#{col}:#{type} #{msg}"
Overcommit::Hook::Message.new(type, file, line, text)
end
end
end
Expand Down

0 comments on commit 8fa77a5

Please sign in to comment.