Class: Puppet::Pops::Validation::DiagnosticFormatter
- Defined in:
- lib/puppet/pops/validation.rb
Overview
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.
Direct Known Subclasses
Instance Method Summary collapse
- #format(diagnostic) ⇒ Object
- #format_location(diagnostic) ⇒ Object
- #format_message(diagnostic) ⇒ Object
-
#format_severity(diagnostic) ⇒ Object
This produces “Deprecation notice: ” prefix if the diagnostic has :deprecation severity, otherwise “”.
Instance Method Details
#format(diagnostic) ⇒ Object
234 235 236 |
# File 'lib/puppet/pops/validation.rb', line 234 def format diagnostic "#{loc(diagnostic)} #{format_severity(diagnostic)}#{format_message(diagnostic)}" end |
#format_location(diagnostic) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/puppet/pops/validation.rb', line 251 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 "#{file}:#{line}:#{pos}:" elsif file && line "#{file}:#{line}:" elsif file "#{file}:" else "" end end |
#format_message(diagnostic) ⇒ Object
238 239 240 |
# File 'lib/puppet/pops/validation.rb', line 238 def diagnostic diagnostic.issue.format(diagnostic.arguments) end |
#format_severity(diagnostic) ⇒ Object
Note:
Note that it is not a good idea to use Puppet.deprecation_warning as it is for internal deprecation.
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.
247 248 249 |
# File 'lib/puppet/pops/validation.rb', line 247 def format_severity diagnostic diagnostic.severity == :deprecation ? "Deprecation notice: " : "" end |