Class: PDK::Validate::PuppetLint

Inherits:
BaseValidator show all
Defined in:
lib/pdk/validate/puppet/puppet_lint.rb

Constant Summary

Constants inherited from BaseValidator

BaseValidator::ALLOW_EMPTY_TARGETS, BaseValidator::IGNORE_DOTFILES, BaseValidator::INVOKE_STYLE

Class Method Summary collapse

Methods inherited from BaseValidator

allow_empty_targets?, cmd_path, ignore_dotfiles?, ignore_pathspec, invoke, parse_targets, process_invalid, process_skipped

Class Method Details

.cmdObject



13
14
15
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 13

def self.cmd
  'puppet-lint'
end

.nameObject



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.parse_options(options, targets)
  cmd_options = ['--json', '--relative']

  cmd_options << '--fix' if options[:auto_correct]

  cmd_options.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

.patternObject



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