Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_root = Overcommit::Utils.repo_root

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_root}/")

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