diff --git a/lib/overcommit/hook/pre_commit/yaml_lint.rb b/lib/overcommit/hook/pre_commit/yaml_lint.rb index a29bd8a0..1fd57513 100644 --- a/lib/overcommit/hook/pre_commit/yaml_lint.rb +++ b/lib/overcommit/hook/pre_commit/yaml_lint.rb @@ -5,15 +5,34 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/adrienverge/yamllint class YamlLint < Base + MESSAGE_REGEX = / + ^(?.+) + :(?\d+) + :(?\d+) + :\s\[(?\w+)\] + \s(?.+)$ + /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