module Overcommit::Hook::PreCommit
  # Checks the syntax of any modified YAML files.
  class YamlSyntax < Base
    def run
      output = []

      applicable_files.each do |file|
        begin
          YAML.load_file(file)
        rescue ArgumentError => e
          output << "#{e.message} parsing #{file}"
        end
      end

      return :pass if output.empty?

      [:fail, output]
    end
  end
end

module Overcommit::Hook::PreCommit
  # Checks the syntax of any modified YAML files.
  class YamlSyntax < Base
    def run
      messages = []

      applicable_files.each do |file|
        begin
          YAML.load_file(file)
        rescue ArgumentError, Psych::SyntaxError => e
          messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
        end
      end

      messages
    end
  end
end

Change YamlSyntax hook to use hook messages
Change YamlSyntax hook to use hook messages

Similar to JsonSyntax, simplify this hook to return hook messages,
allowing the framework to determine if a run passed or failed.

Change-Id: Ia3c2cdc569752b0ec6edf8f4c81d4a5ef07be9d1
Reviewed-on: http://gerrit.causes.com/47213
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@brigade.com>
Reviewed-by: Shane da Silva <67fb7bfe39f841b16a1f86d3928acc568d12c716@brigade.com>
