class Puppet::Pops::Validation::DiagnosticFormatter

Formats a diagnostic for output. Produces a diagnostic output typical for a compiler (suitable for interpretation by tools) The format is: `file:line:pos: Message`, where pos, line and file are included if available.

Public Instance Methods

format(diagnostic) click to toggle source
# File lib/puppet/pops/validation.rb, line 261
def format diagnostic
  "#{loc(diagnostic)} #{format_severity(diagnostic)}#{format_message(diagnostic)}"
end
format_location(diagnostic) click to toggle source
# File lib/puppet/pops/validation.rb, line 278
def format_location diagnostic
  file = diagnostic.file
  file = (file.is_a?(String) && file.empty?) ? nil : file
  line = pos = nil
  if diagnostic.source_pos
    line = diagnostic.source_pos.line
    pos = diagnostic.source_pos.pos
  end
  if file && line && pos
    "#{file}:#{line}:#{pos}:"
  elsif file && line
    "#{file}:#{line}:"
  elsif file
    "#{file}:"
  else
    ""
  end
end
format_message(diagnostic) click to toggle source
# File lib/puppet/pops/validation.rb, line 265
def format_message diagnostic
  diagnostic.issue.format(diagnostic.arguments)
end
format_severity(diagnostic) click to toggle source

This produces “Deprecation notice: ” prefix if the diagnostic has :deprecation severity, otherwise “”. The idea is that all other diagnostics are emitted with the methods Puppet.err (or an exception), and Puppet.warning. @note Note that it is not a good idea to use Puppet.deprecation_warning as it is for internal deprecation.

# File lib/puppet/pops/validation.rb, line 274
def format_severity diagnostic
  diagnostic.severity == :deprecation ? "Deprecation notice: " : ""
end