Class: Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle

Inherits:
DiagnosticFormatter show all
Defined in:
lib/puppet/pops/validation.rb

Overview

Produces a diagnostic output in the “puppet style”, where the location is appended with an “at …” if the location is known.

Instance Method Summary collapse

Methods inherited from DiagnosticFormatter

#format_message, #format_severity

Instance Method Details

#format(diagnostic) ⇒ Object



307
308
309
310
311
312
313
# File 'lib/puppet/pops/validation.rb', line 307

def format diagnostic
  if (location = format_location diagnostic) != ""
    "#{format_severity(diagnostic)}#{format_message(diagnostic)}#{location}"
  else
    format_message(diagnostic)
  end
end

#format_location(diagnostic) ⇒ Object

The somewhat (machine) unusable format in current use by puppet. have to be used here for backwards compatibility.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/puppet/pops/validation.rb', line 317

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
    " at #{file}:#{line}:#{pos}"
  elsif file && line
    " at #{file}:#{line}"
  elsif line && pos
    " at line #{line}:#{pos}"
  elsif line
    " at line #{line}"
  elsif file
    " in #{file}"
  else
    ""
  end
end