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



274
275
276
277
278
279
280
# File 'lib/puppet/pops/validation.rb', line 274

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.



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/puppet/pops/validation.rb', line 284

def format_location diagnostic
  file = diagnostic.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 and line
    " at #{file}:#{line}"
  elsif line && pos
    " at line #{line}:#{pos}"
  elsif line
    " at line #{line}"
  elsif file
    " in #{file}"
  else
    ""
  end
end