Class: PDK::Validate::PuppetSyntax
Constant Summary
BaseValidator::INVOKE_STYLE
Class Method Summary
collapse
cmd_path, invoke, parse_targets, process_invalid, process_skipped
Class Method Details
.cmd ⇒ Object
12
13
14
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 12
def self.cmd
'puppet'
end
|
.name ⇒ Object
8
9
10
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 8
def self.name
'puppet-syntax'
end
|
.parse_options(_options, targets) ⇒ Object
24
25
26
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 24
def self.parse_options(_options, targets)
%w[parser validate].concat(targets)
end
|
.parse_output(report, result, targets) ⇒ Object
28
29
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 28
def self.parse_output(report, result, targets)
output = result[:stderr].split("\n")
results_data = []
output.each do |offense|
sanitize_console_output(offense)
message, _at, location_raw = offense.partition(' at ')
severity, _colon, message = message.rpartition(': ')
location = location_raw.strip.match(%r{\A(?<file>.+):(?<line>\d+):(?<column>\d+)\Z}) unless location_raw.nil?
attributes = {
source: name,
message: message.strip,
state: :failure,
}
attributes[:severity] = severity.strip unless severity.nil?
unless location.nil?
attributes[:file] = location[:file]
attributes[:line] = location[:line]
attributes[:column] = location[:column]
end
results_data << attributes
end
targets.reject { |target| results_data.any? { |j| j[:file] == target } }.each do |target|
report.add_event(
file: target,
source: name,
severity: :ok,
state: :passed,
)
end
results_data.each do |offense|
report.add_event(offense)
end
end
|
.pattern ⇒ Object
16
17
18
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 16
def self.pattern
'**/**.pp'
end
|
.sanitize_console_output(line) ⇒ Object
77
78
79
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 77
def self.sanitize_console_output(line)
line.gsub!(%r{\e\[([;\d]+)?m}, '')
end
|
.spinner_text(_targets = nil) ⇒ Object
20
21
22
|
# File 'lib/pdk/validators/puppet/puppet_syntax.rb', line 20
def self.spinner_text(_targets = nil)
_('Checking Puppet manifest syntax (%{pattern})') % { pattern: pattern }
end
|