Method: PDK::Validate::PuppetSyntax.parse_output

Defined in:
lib/pdk/validate/puppet/puppet_syntax.rb

.parse_output(report, result, targets) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pdk/validate/puppet/puppet_syntax.rb', line 56

def self.parse_output(report, result, targets)
  # Due to PUP-7504, we will have to programmatically construct the json
  # object from the text output for now.
  output = result[:stderr].split("\n").reject { |entry| entry.empty? }

  results_data = []
  output.each do |offense|
    offense_data = parse_offense(offense)
    results_data << offense_data
  end

  # puppet parser validate does not include files without problems in its
  # output, so we need to go through the list of targets and add passing
  # events to the report for any target not listed in the output.
  targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
    report.add_event(
      file:     target,
      source:   name,
      severity: :ok,
      state:    :passed,
    )
  end

  results_data.each do |offense|
    report.add_event(offense)
  end
end