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



10
11
12
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 10

def self.cmd
  'puppet-lint'
end

.nameObject



6
7
8
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 6

def self.name
  'puppet-lint'
end

.parse_options(options, targets) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 22

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



30
31
32
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
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 30

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



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

def self.pattern
  '**/*.pp'
end

.spinner_text(_targets = nil) ⇒ Object



18
19
20
# File 'lib/pdk/validate/puppet/puppet_lint.rb', line 18

def self.spinner_text(_targets = nil)
  _('Checking Puppet manifest style (%{pattern}).') % { pattern: pattern }
end