Class: PDK::Validate::PuppetLint
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- PDK::Validate::PuppetLint
- Defined in:
- lib/pdk/validate/puppet/puppet_lint.rb
Constant Summary
Constants inherited from BaseValidator
Class Method Summary collapse
- .cmd ⇒ Object
- .name ⇒ Object
- .parse_options(options, targets) ⇒ Object
- .parse_output(report, result, targets) ⇒ Object
- .pattern ⇒ Object
- .spinner_text(_targets = nil) ⇒ Object
Methods inherited from BaseValidator
cmd_path, invoke, parse_targets, process_invalid, process_skipped
Class Method Details
.cmd ⇒ Object
13 14 15 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 13 def self.cmd 'puppet-lint' end |
.name ⇒ Object
9 10 11 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 9 def self.name 'puppet-lint' end |
.parse_options(options, targets) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 25 def self.(, targets) = ['--json', '--relative'] << '--fix' if [:auto_correct] .concat(targets) end |
.parse_output(report, result, targets) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 33 def self.parse_output(report, result, targets) begin json_data = JSON.parse(result[:stdout]).flatten rescue JSON::ParserError raise PDK::Validate::ParseOutputError, result[:stdout] end # puppet-lint does not include files without problems in its JSON # output, so we need to go through the list of targets and add passing # events to the report for any target not listed in the JSON output. targets.reject { |target| json_data.any? { |j| j['path'] == target } }.each do |target| report.add_event( file: target, source: name, severity: 'ok', state: :passed, ) end json_data.each do |offense| report.add_event( file: offense['path'], source: name, line: offense['line'], column: offense['column'], message: offense['message'], test: offense['check'], severity: (offense['kind'] == 'fixed') ? 'corrected' : offense['kind'], state: :failure, ) end end |
.pattern ⇒ Object
17 18 19 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 17 def self.pattern '**/*.pp' end |
.spinner_text(_targets = nil) ⇒ Object
21 22 23 |
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 21 def self.spinner_text(_targets = nil) _('Checking Puppet manifest style (%{pattern}).') % { pattern: pattern } end |