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
272 def format diagnostic
273   "#{format_location(diagnostic)} #{format_severity(diagnostic)}#{format_message(diagnostic)}"
274 end
format_location(diagnostic) click to toggle source
    # File lib/puppet/pops/validation.rb
289 def format_location diagnostic
290   file = diagnostic.file
291   file = (file.is_a?(String) && file.empty?) ? nil : file
292   line = pos = nil
293   if diagnostic.source_pos
294     line = diagnostic.source_pos.line
295     pos = diagnostic.source_pos.pos
296   end
297   if file && line && pos
298     "#{file}:#{line}:#{pos}:"
299   elsif file && line
300     "#{file}:#{line}:"
301   elsif file
302     "#{file}:"
303   else
304     ""
305   end
306 end
format_message(diagnostic) click to toggle source
    # File lib/puppet/pops/validation.rb
276 def format_message diagnostic
277   diagnostic.issue.format(diagnostic.arguments)
278 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
285 def format_severity diagnostic
286   diagnostic.severity == :deprecation ? "Deprecation notice: " : ""
287 end