lib/puppet-check/puppet_parser.rb in puppet-check-2.0.1 vs lib/puppet-check/puppet_parser.rb in puppet-check-2.1.0

- old
+ new

@@ -1,7 +1,7 @@ require 'puppet' -require_relative '../puppet-check' +require_relative '../puppet_check' # executes diagnostics on puppet files class PuppetParser # checks puppet (.pp) def self.manifest(files, style, pl_args) @@ -26,17 +26,18 @@ message = new_error.values.map(&:to_s).join("\n").gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '') end # this is the actual error that we need to rescue Puppet::Face from rescue SystemExit # puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info - if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.4') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.5') - message = errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '') - # puppet 5.0-5.2 can only do one error per line and outputs fake dir env info - elsif Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.3') - message = errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '') - end - # puppet < 5 and 5.3 parser output style - message = errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '') + message = if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.4') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.5') + errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '') + # puppet 5.0-5.2 can only do one error per line and outputs fake dir env info + elsif Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.3') + errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '') + # puppet < 5 and 5.3 parser output style + else + errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '') + end end # output message next PuppetCheck.settings[:error_files].push("#{file}:\n#{message}") unless message.empty? # initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit