puppet-lint 4.3.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/puppet-lint/checkplugin.rb +6 -4
- data/lib/puppet-lint/checks.rb +6 -3
- data/lib/puppet-lint/configuration.rb +1 -1
- data/lib/puppet-lint/data.rb +4 -27
- data/lib/puppet-lint/lexer/string_slurper.rb +6 -6
- data/lib/puppet-lint/lexer.rb +40 -3
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +1 -1
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +1 -1
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +1 -1
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +1 -1
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +1 -1
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +1 -1
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +1 -1
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +1 -1
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +2 -2
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +2 -2
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +1 -1
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +1 -1
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +1 -1
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +1 -1
- data/lib/puppet-lint/plugins/check_whitespace/space_before_arrow.rb +2 -2
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +1 -1
- data/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +2 -2
- data/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +1 -1
- data/lib/puppet-lint/plugins.rb +1 -1
- data/lib/puppet-lint/report/codeclimate.rb +1 -1
- data/lib/puppet-lint/tasks/puppet-lint.rb +2 -2
- data/lib/puppet-lint/tasks/release_test.rb +2 -2
- data/lib/puppet-lint/version.rb +1 -1
- data/lib/puppet-lint.rb +2 -3
- data/rubocop_baseline.yml +1 -1
- data/spec/acceptance/puppet_lint_spec.rb +7 -0
- data/spec/fixtures/test/manifests/parseable.yaml +3 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/puppet-lint/checkplugin_spec.rb +36 -0
- data/spec/unit/puppet-lint/checks_spec.rb +0 -5
- data/spec/unit/puppet-lint/lexer_spec.rb +6 -0
- metadata +6 -5
- data/lib/puppet-lint/monkeypatches.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 200023e7df4e5c5ad823fba0f940ee2ad73ae5d05eb04796e83dbcc118e2a47e
|
4
|
+
data.tar.gz: 3a14e87f1f69fdc2495068d246609af04c81e6610e4e878a669ab9b8262f1265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bad4d387c8695aa0bc3fca805a819c5af1e0c410953f61093ec77a1139848c1b284a53aa238bed450ba5195d9af8736a2ba6a9dfec97ceca09bdaca08da80bf
|
7
|
+
data.tar.gz: 4d26e6093580630b0b838562efdc2d2e9492d8185652a469aaca3fdb48cec0f88b9d02367cacc595b46d10d08745d4b76874d304a891e1e265c35ffb01625752
|
@@ -55,7 +55,9 @@ class PuppetLint::CheckPlugin
|
|
55
55
|
#
|
56
56
|
# Returns an Array of PuppetLint::Lexer::Token objects.
|
57
57
|
def tokens
|
58
|
-
|
58
|
+
# When called from a plugins `check` method, the tokens array returned should be a (shallow) copy
|
59
|
+
called_from_check = (caller_locations(1..1).first.base_label == 'check')
|
60
|
+
PuppetLint::Data.tokens(duplicate: called_from_check)
|
59
61
|
end
|
60
62
|
|
61
63
|
def add_token(index, token)
|
@@ -180,9 +182,9 @@ class PuppetLint::CheckPlugin
|
|
180
182
|
def default_info
|
181
183
|
@default_info ||= {
|
182
184
|
check: self.class.const_get(:NAME),
|
183
|
-
fullpath
|
184
|
-
path
|
185
|
-
filename:
|
185
|
+
fullpath:,
|
186
|
+
path:,
|
187
|
+
filename:
|
186
188
|
}
|
187
189
|
end
|
188
190
|
|
data/lib/puppet-lint/checks.rb
CHANGED
@@ -36,7 +36,7 @@ class PuppetLint::Checks
|
|
36
36
|
problems << {
|
37
37
|
kind: :error,
|
38
38
|
check: :syntax,
|
39
|
-
message
|
39
|
+
message:,
|
40
40
|
line: e.line_no,
|
41
41
|
column: e.column,
|
42
42
|
fullpath: PuppetLint::Data.fullpath,
|
@@ -54,10 +54,11 @@ class PuppetLint::Checks
|
|
54
54
|
#
|
55
55
|
# Returns an Array of problem Hashes.
|
56
56
|
def run(fileinfo, data)
|
57
|
-
load_data(fileinfo, data)
|
58
|
-
|
59
57
|
checks_run = []
|
60
58
|
if File.extname(fileinfo).downcase.match?(%r{\.ya?ml$})
|
59
|
+
PuppetLint::Data.path = fileinfo
|
60
|
+
PuppetLint::Data.manifest_lines = data.split("\n", -1)
|
61
|
+
|
61
62
|
enabled_checks.select { |check| YAML_COMPATIBLE_CHECKS.include?(check) }.each do |check|
|
62
63
|
klass = PuppetLint.configuration.check_object[check].new
|
63
64
|
# FIXME: shadowing #problems
|
@@ -65,6 +66,8 @@ class PuppetLint::Checks
|
|
65
66
|
checks_run << [klass, problems]
|
66
67
|
end
|
67
68
|
else
|
69
|
+
load_data(fileinfo, data)
|
70
|
+
|
68
71
|
enabled_checks.each do |check|
|
69
72
|
klass = PuppetLint.configuration.check_object[check].new
|
70
73
|
# FIXME: shadowing #problems
|
data/lib/puppet-lint/data.rb
CHANGED
@@ -38,37 +38,14 @@ class PuppetLint::Data
|
|
38
38
|
@defaults_indexes = nil
|
39
39
|
end
|
40
40
|
|
41
|
-
# @api private
|
42
|
-
def ruby1?
|
43
|
-
@ruby1 = RbConfig::CONFIG['MAJOR'] == '1' if @ruby1.nil?
|
44
|
-
@ruby1
|
45
|
-
end
|
46
|
-
|
47
41
|
# Get the tokenised manifest.
|
48
42
|
#
|
43
|
+
# @param duplicate [Boolean] if true, returns a duplicate of the token array.
|
49
44
|
# @return [Array[PuppetLint::Lexer::Token]]
|
50
45
|
#
|
51
46
|
# @api public
|
52
|
-
def tokens
|
53
|
-
|
54
|
-
begin
|
55
|
-
caller[0][%r{`.*'}][1..-2] # rubocop:disable Performance/Caller
|
56
|
-
rescue NoMethodError
|
57
|
-
caller[1][%r{`.*'}][1..-2] # rubocop:disable Performance/Caller
|
58
|
-
end
|
59
|
-
else
|
60
|
-
begin
|
61
|
-
caller(0..0).first[%r{`.*'}][1..-2]
|
62
|
-
rescue NoMethodError
|
63
|
-
caller(1..1).first[%r{`.*'}][1..-2]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
if calling_method == 'check'
|
68
|
-
@tokens.dup
|
69
|
-
else
|
70
|
-
@tokens
|
71
|
-
end
|
47
|
+
def tokens(duplicate: false)
|
48
|
+
duplicate ? @tokens.dup : @tokens
|
72
49
|
end
|
73
50
|
|
74
51
|
# Add new token.
|
@@ -359,7 +336,7 @@ class PuppetLint::Data
|
|
359
336
|
end: i + j + 1,
|
360
337
|
tokens: tokens[i..(i + j + 1)],
|
361
338
|
param_tokens: param_tokens(tokens[i..(i + j + 1)]),
|
362
|
-
type
|
339
|
+
type:,
|
363
340
|
name_token: token.next_code_token,
|
364
341
|
inherited_token: inherited_class
|
365
342
|
}
|
@@ -6,12 +6,12 @@ class PuppetLint::Lexer
|
|
6
6
|
class StringSlurper
|
7
7
|
attr_accessor :scanner, :results, :interp_stack
|
8
8
|
|
9
|
-
START_INTERP_PATTERN = %r{\$\{}
|
10
|
-
END_INTERP_PATTERN = %r{\}}
|
11
|
-
END_STRING_PATTERN = %r{(\A|[^\\])(\\\\)*"}
|
12
|
-
UNENC_VAR_PATTERN = %r{(\A|[^\\])\$(::)?(\w+(-\w+)*::)*\w+(-\w+)*}
|
13
|
-
ESC_DQUOTE_PATTERN = %r{\\+"}
|
14
|
-
LBRACE_PATTERN = %r{\{}
|
9
|
+
START_INTERP_PATTERN = %r{\$\{}
|
10
|
+
END_INTERP_PATTERN = %r{\}}
|
11
|
+
END_STRING_PATTERN = %r{(\A|[^\\])(\\\\)*"}
|
12
|
+
UNENC_VAR_PATTERN = %r{(\A|[^\\])\$(::)?(\w+(-\w+)*::)*\w+(-\w+)*}
|
13
|
+
ESC_DQUOTE_PATTERN = %r{\\+"}
|
14
|
+
LBRACE_PATTERN = %r{\{}
|
15
15
|
|
16
16
|
def initialize(string)
|
17
17
|
@scanner = StringScanner.new(string)
|
data/lib/puppet-lint/lexer.rb
CHANGED
@@ -111,9 +111,9 @@ class PuppetLint::Lexer
|
|
111
111
|
# \p{Zs} == ASCII + Unicode non-linebreaking whitespace
|
112
112
|
WHITESPACE_RE = (RUBY_VERSION == '1.8.7') ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]}
|
113
113
|
|
114
|
-
LINE_END_RE = %r{(?:\r\n|\r|\n)}
|
114
|
+
LINE_END_RE = %r{(?:\r\n|\r|\n)}
|
115
115
|
|
116
|
-
NAME_RE = %r{\A((?:(?:::)?[_a-z0-9][-\w]*)(?:::[a-z0-9][-\w]*)*)}
|
116
|
+
NAME_RE = %r{\A((?:(?:::)?[_a-z0-9][-\w]*)(?:::[a-z0-9][-\w]*)*)}
|
117
117
|
|
118
118
|
# Internal: An Array of Arrays containing tokens that can be described by
|
119
119
|
# a single regular expression. Each sub-Array contains 2 elements, the
|
@@ -123,7 +123,44 @@ class PuppetLint::Lexer
|
|
123
123
|
[:WHITESPACE, %r{\A(#{WHITESPACE_RE}+)}],
|
124
124
|
# FIXME: Future breaking change, the following :TYPE tokens conflict with
|
125
125
|
# the :TYPE keyword token.
|
126
|
-
[:TYPE, %r{\A(
|
126
|
+
[:TYPE, %r{\A(
|
127
|
+
Any|
|
128
|
+
Array|
|
129
|
+
Binary|
|
130
|
+
Boolean|
|
131
|
+
Callable|
|
132
|
+
CatalogEntry|
|
133
|
+
Class|
|
134
|
+
Collection|
|
135
|
+
Data|
|
136
|
+
Default|
|
137
|
+
Enum|
|
138
|
+
Error|
|
139
|
+
Float|
|
140
|
+
Hash|
|
141
|
+
Integer|
|
142
|
+
Iterable|
|
143
|
+
Iterator|
|
144
|
+
NotUndef|
|
145
|
+
Numeric|
|
146
|
+
Optional|
|
147
|
+
Pattern|
|
148
|
+
Regexp|
|
149
|
+
Resource|
|
150
|
+
RichData|
|
151
|
+
Runtime|
|
152
|
+
Scalar|
|
153
|
+
ScalarData|
|
154
|
+
SemVer|
|
155
|
+
SemVerRange|
|
156
|
+
Sensitive|
|
157
|
+
String|
|
158
|
+
Struct|
|
159
|
+
Tuple|
|
160
|
+
Type|
|
161
|
+
Undef|
|
162
|
+
Variant
|
163
|
+
)\b}x],
|
127
164
|
[:CLASSREF, %r{\A(((::){0,1}[A-Z][-\w]*)+)}],
|
128
165
|
[:NUMBER, %r{\A\b((?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?))\b}],
|
129
166
|
[:FUNCTION_NAME, %r{#{NAME_RE}(?=\()}],
|
@@ -12,7 +12,7 @@ PuppetLint.new_check(:arrow_on_right_operand_line) do
|
|
12
12
|
message: "arrow should be on the right operand's line",
|
13
13
|
line: token.line,
|
14
14
|
column: token.column,
|
15
|
-
token
|
15
|
+
token:,
|
16
16
|
description: 'Test the manifest tokens for chaining arrow that is on the line of the left operand when the right operand is on another line.',
|
17
17
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#chaining-arrow-syntax',
|
18
18
|
)
|
@@ -12,7 +12,7 @@ PuppetLint.new_check(:slash_comments) do
|
|
12
12
|
message: '// comment found',
|
13
13
|
line: token.line,
|
14
14
|
column: token.column,
|
15
|
-
token
|
15
|
+
token:,
|
16
16
|
description: 'Check the manifest tokens for any comments started with slashes (//) and record a warning for each instance found.',
|
17
17
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#comments',
|
18
18
|
)
|
@@ -12,7 +12,7 @@ PuppetLint.new_check(:star_comments) do
|
|
12
12
|
message: '/* */ comment found',
|
13
13
|
line: token.line,
|
14
14
|
column: token.column,
|
15
|
-
token
|
15
|
+
token:,
|
16
16
|
description: 'Check the manifest tokens for any comments encapsulated with slash-asterisks (/* */) and record a warning for each instance found.',
|
17
17
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#comments',
|
18
18
|
)
|
@@ -31,7 +31,7 @@ PuppetLint.new_check(:unquoted_node_name) do
|
|
31
31
|
message: 'unquoted node name found',
|
32
32
|
line: token.line,
|
33
33
|
column: token.column,
|
34
|
-
token
|
34
|
+
token:,
|
35
35
|
description: 'Check the manifest for unquoted node names and record a warning for each instance found.',
|
36
36
|
help_uri: nil,
|
37
37
|
)
|
@@ -20,7 +20,7 @@ PuppetLint.new_check(:ensure_first_param) do
|
|
20
20
|
message: "ensure found on line but it's not the first attribute",
|
21
21
|
line: ensure_token.line,
|
22
22
|
column: ensure_token.column,
|
23
|
-
resource
|
23
|
+
resource:,
|
24
24
|
description: 'Check the tokens of each resource instance for an ensure parameter and if ' \
|
25
25
|
'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.',
|
26
26
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering',
|
@@ -20,7 +20,7 @@ PuppetLint.new_check(:ensure_not_symlink_target) do
|
|
20
20
|
line: value_token.line,
|
21
21
|
column: value_token.column,
|
22
22
|
param_token: ensure_token,
|
23
|
-
value_token
|
23
|
+
value_token:,
|
24
24
|
description: 'Check the tokens of each File resource instance for an ensure parameter and ' \
|
25
25
|
'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').',
|
26
26
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links',
|
@@ -6,7 +6,7 @@
|
|
6
6
|
MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze
|
7
7
|
SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze
|
8
8
|
IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME]
|
9
|
-
MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}
|
9
|
+
MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}
|
10
10
|
|
11
11
|
PuppetLint.new_check(:file_mode) do
|
12
12
|
def check
|
@@ -12,7 +12,7 @@ PuppetLint.new_check(:unquoted_resource_title) do
|
|
12
12
|
message: 'unquoted resource title',
|
13
13
|
line: token.line,
|
14
14
|
column: token.column,
|
15
|
-
token
|
15
|
+
token:,
|
16
16
|
description: 'Check the manifest tokens for any resource titles / namevars that are not quoted and record a warning for each instance found.',
|
17
17
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#resource-names',
|
18
18
|
)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# each instance found.
|
4
4
|
#
|
5
5
|
# https://puppet.com/docs/puppet/latest/style_guide.html#quoting
|
6
|
-
ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}
|
6
|
+
ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}
|
7
7
|
|
8
8
|
PuppetLint.new_check(:double_quoted_strings) do
|
9
9
|
def check
|
@@ -18,7 +18,7 @@ PuppetLint.new_check(:double_quoted_strings) do
|
|
18
18
|
message: 'double quoted string containing no variables',
|
19
19
|
line: token.line,
|
20
20
|
column: token.column,
|
21
|
-
token
|
21
|
+
token:,
|
22
22
|
description: 'Check the manifest tokens for any double quoted strings that don\'t ' \
|
23
23
|
'contain any variables or common escape characters and record a warning for each instance found.',
|
24
24
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
|
@@ -27,8 +27,8 @@ PuppetLint.new_check(:only_variable_string) do
|
|
27
27
|
message: 'string containing only a variable',
|
28
28
|
line: var_token.line,
|
29
29
|
column: var_token.column,
|
30
|
-
start_token
|
31
|
-
var_token
|
30
|
+
start_token:,
|
31
|
+
var_token:,
|
32
32
|
end_token: eos_token,
|
33
33
|
description: 'Check the manifest tokens for double quoted strings that contain a single variable only and record a warning for each instance found.',
|
34
34
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
|
@@ -19,7 +19,7 @@ PuppetLint.new_check(:puppet_url_without_modules) do
|
|
19
19
|
message: 'puppet:// URL without modules/ found',
|
20
20
|
line: token.line,
|
21
21
|
column: token.column,
|
22
|
-
token
|
22
|
+
token:,
|
23
23
|
description: 'Check the manifest tokens for any puppet:// URL strings where the path section doesn\'t start with modules/ and record a warning for each instance found.',
|
24
24
|
help_uri: nil,
|
25
25
|
)
|
@@ -18,7 +18,7 @@ PuppetLint.new_check(:quoted_booleans) do
|
|
18
18
|
message: 'quoted boolean value found',
|
19
19
|
line: token.line,
|
20
20
|
column: token.column,
|
21
|
-
token
|
21
|
+
token:,
|
22
22
|
description: 'Check the manifest tokens for any double or single quoted strings containing only a boolean value and record a warning for each instance found.',
|
23
23
|
help_uri: nil,
|
24
24
|
)
|
@@ -25,7 +25,7 @@ PuppetLint.new_check(:variables_not_enclosed) do
|
|
25
25
|
message: 'variable not enclosed in {}',
|
26
26
|
line: token.line,
|
27
27
|
column: token.column,
|
28
|
-
token
|
28
|
+
token:,
|
29
29
|
description: 'Check the manifest tokens for any variables in a string that have not been enclosed by braces ({}) and record a warning for each instance found.',
|
30
30
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
|
31
31
|
)
|
@@ -16,7 +16,7 @@ PuppetLint.new_check(:hard_tabs) do
|
|
16
16
|
message: 'tab character found',
|
17
17
|
line: token.line,
|
18
18
|
column: token.column,
|
19
|
-
token
|
19
|
+
token:,
|
20
20
|
description: 'Check the raw manifest string for lines containing hard tab characters and record an error for each instance found.',
|
21
21
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
|
22
22
|
)
|
@@ -18,7 +18,7 @@ PuppetLint.new_check(:trailing_whitespace) do
|
|
18
18
|
message: 'trailing whitespace found',
|
19
19
|
line: token.line,
|
20
20
|
column: token.column,
|
21
|
-
token
|
21
|
+
token:,
|
22
22
|
description: 'Check the manifest tokens for lines ending with whitespace and record an error for each instance found.',
|
23
23
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
|
24
24
|
)
|
data/lib/puppet-lint/plugins.rb
CHANGED
@@ -27,7 +27,7 @@ class PuppetLint::RakeTask < Rake::TaskLib
|
|
27
27
|
#
|
28
28
|
# PuppetLint::RakeTask.new
|
29
29
|
# rubocop:disable Lint/MissingSuper
|
30
|
-
def initialize(*args, &
|
30
|
+
def initialize(*args, &)
|
31
31
|
@name = args.shift || :lint
|
32
32
|
@pattern = DEFAULT_PATTERN
|
33
33
|
@with_filename = true
|
@@ -35,7 +35,7 @@ class PuppetLint::RakeTask < Rake::TaskLib
|
|
35
35
|
@only_checks = []
|
36
36
|
@ignore_paths = []
|
37
37
|
|
38
|
-
define(args, &
|
38
|
+
define(args, &)
|
39
39
|
end
|
40
40
|
|
41
41
|
def define(args, &task_block)
|
@@ -27,7 +27,7 @@ def run_cmd(message, *cmd)
|
|
27
27
|
[output.strip, status.success?]
|
28
28
|
end
|
29
29
|
|
30
|
-
def with_puppet_lint_head(&
|
30
|
+
def with_puppet_lint_head(&)
|
31
31
|
print(' Updating Gemfile to use puppet-lint HEAD... ')
|
32
32
|
|
33
33
|
buffer = Parser::Source::Buffer.new('Gemfile')
|
@@ -49,7 +49,7 @@ def with_puppet_lint_head(&block)
|
|
49
49
|
|
50
50
|
puts 'Done'
|
51
51
|
|
52
|
-
Bundler.with_clean_env(&
|
52
|
+
Bundler.with_clean_env(&)
|
53
53
|
|
54
54
|
run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile')
|
55
55
|
end
|
data/lib/puppet-lint/version.rb
CHANGED
data/lib/puppet-lint.rb
CHANGED
@@ -11,7 +11,6 @@ require 'puppet-lint/data'
|
|
11
11
|
require 'puppet-lint/checks'
|
12
12
|
require 'puppet-lint/report/github'
|
13
13
|
require 'puppet-lint/bin'
|
14
|
-
require 'puppet-lint/monkeypatches'
|
15
14
|
|
16
15
|
class PuppetLint::NoCodeError < StandardError; end
|
17
16
|
|
@@ -250,11 +249,11 @@ class PuppetLint
|
|
250
249
|
# def check
|
251
250
|
# end
|
252
251
|
# end
|
253
|
-
def self.new_check(name, &
|
252
|
+
def self.new_check(name, &)
|
254
253
|
class_name = name.to_s.split('_').map(&:capitalize).join
|
255
254
|
klass = PuppetLint.const_set(:"Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
|
256
255
|
klass.const_set(:NAME, name)
|
257
|
-
klass.class_exec(&
|
256
|
+
klass.class_exec(&)
|
258
257
|
PuppetLint.configuration.add_check(name, klass)
|
259
258
|
PuppetLint::Data.ignore_overrides[name] ||= {}
|
260
259
|
end
|
data/rubocop_baseline.yml
CHANGED
@@ -43,4 +43,11 @@ describe 'When executing puppet-lint' do
|
|
43
43
|
expect(result[:stdout]).to have_warnings(2)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
context 'with a YAML file provided' do
|
48
|
+
it 'returns zero errors' do
|
49
|
+
result = puppet_lint([File.join(manifest_root, 'parseable.yaml')])
|
50
|
+
expect(result[:stdout]).to have_errors(0)
|
51
|
+
end
|
52
|
+
end
|
46
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,6 +22,7 @@ end
|
|
22
22
|
|
23
23
|
require 'puppet-lint'
|
24
24
|
require 'rspec/its'
|
25
|
+
require 'pp'
|
25
26
|
begin
|
26
27
|
require 'rspec/json_expectations'
|
27
28
|
rescue LoadError, SyntaxError
|
@@ -33,7 +34,7 @@ module RSpec::LintExampleGroup
|
|
33
34
|
def initialize(method, message)
|
34
35
|
@expected_problem = {
|
35
36
|
kind: method.to_s.delete_prefix('contain_').to_sym,
|
36
|
-
message:
|
37
|
+
message:
|
37
38
|
}
|
38
39
|
@description = ["contain a #{@expected_problem[:kind]}"]
|
39
40
|
end
|
@@ -107,7 +108,7 @@ module RSpec::LintExampleGroup
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
def method_missing(method, *args, &
|
111
|
+
def method_missing(method, *args, &)
|
111
112
|
return HaveProblem.new(method, args.first) if method.to_s.start_with?('contain_')
|
112
113
|
|
113
114
|
super
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyCheckPlugin < PuppetLint::CheckPlugin
|
4
|
+
def check
|
5
|
+
# Since we're calling `tokens` from a `check` method, we should get our own Array object.
|
6
|
+
# If we add an extra token to it, PuppetLint::Data.tokens should remain unchanged.
|
7
|
+
tokens << :extra_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def fix
|
11
|
+
tokens << :fix_token
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe PuppetLint::CheckPlugin do
|
16
|
+
before(:each) do
|
17
|
+
PuppetLint::Data.tokens = [:token1, :token2, :token3]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns a duplicate of the token array when called from check' do
|
21
|
+
plugin = DummyCheckPlugin.new
|
22
|
+
|
23
|
+
plugin.check
|
24
|
+
|
25
|
+
# Verify that the global token array remains unchanged.
|
26
|
+
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'other methods can modify the tokens array' do
|
30
|
+
plugin = DummyCheckPlugin.new
|
31
|
+
|
32
|
+
plugin.fix
|
33
|
+
|
34
|
+
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3, :fix_token])
|
35
|
+
end
|
36
|
+
end
|
@@ -223,11 +223,6 @@ describe PuppetLint::Checks do
|
|
223
223
|
allow(File).to receive(:extname).with(fileinfo).and_return('.yaml')
|
224
224
|
end
|
225
225
|
|
226
|
-
it 'loads the yaml data' do
|
227
|
-
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original # rubocop: disable RSpec/SubjectStub
|
228
|
-
instance.run(fileinfo, data)
|
229
|
-
end
|
230
|
-
|
231
226
|
context 'when there are checks enabled' do
|
232
227
|
let(:enabled_checks) { [:legacy_facts] }
|
233
228
|
let(:enabled_check_classes) { enabled_checks.map { |r| PuppetLint.configuration.check_object[r] } }
|
@@ -1392,6 +1392,12 @@ END
|
|
1392
1392
|
|
1393
1393
|
it_behaves_like 'a type matcher', 'Error'
|
1394
1394
|
it_behaves_like 'a type matcher', 'Binary'
|
1395
|
+
it_behaves_like 'a type matcher', 'Iterable'
|
1396
|
+
it_behaves_like 'a type matcher', 'Iterator'
|
1397
|
+
it_behaves_like 'a type matcher', 'RichData'
|
1398
|
+
it_behaves_like 'a type matcher', 'ScalarData'
|
1399
|
+
it_behaves_like 'a type matcher', 'SemVer'
|
1400
|
+
it_behaves_like 'a type matcher', 'SemVerRange'
|
1395
1401
|
end
|
1396
1402
|
|
1397
1403
|
context ':HEREDOC without interpolation' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2025-
|
13
|
+
date: 2025-09-25 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: " Checks your Puppet manifests against the Puppetlabs style guide
|
16
16
|
and alerts you to any discrepancies.\n"
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- lib/puppet-lint/lexer.rb
|
35
35
|
- lib/puppet-lint/lexer/string_slurper.rb
|
36
36
|
- lib/puppet-lint/lexer/token.rb
|
37
|
-
- lib/puppet-lint/monkeypatches.rb
|
38
37
|
- lib/puppet-lint/optparser.rb
|
39
38
|
- lib/puppet-lint/plugins.rb
|
40
39
|
- lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb
|
@@ -95,6 +94,7 @@ files:
|
|
95
94
|
- spec/fixtures/test/manifests/init.pp
|
96
95
|
- spec/fixtures/test/manifests/malformed.pp
|
97
96
|
- spec/fixtures/test/manifests/mismatched_control_comment.pp
|
97
|
+
- spec/fixtures/test/manifests/parseable.yaml
|
98
98
|
- spec/fixtures/test/manifests/top_scope_variables.pp
|
99
99
|
- spec/fixtures/test/manifests/two_warnings.pp
|
100
100
|
- spec/fixtures/test/manifests/unterminated_control_comment.pp
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- spec/spec_helper_acceptance.rb
|
106
106
|
- spec/spec_helper_acceptance_local.rb
|
107
107
|
- spec/unit/puppet-lint/bin_spec.rb
|
108
|
+
- spec/unit/puppet-lint/checkplugin_spec.rb
|
108
109
|
- spec/unit/puppet-lint/checks_spec.rb
|
109
110
|
- spec/unit/puppet-lint/configuration_spec.rb
|
110
111
|
- spec/unit/puppet-lint/data_spec.rb
|
@@ -165,14 +166,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
requirements:
|
166
167
|
- - ">="
|
167
168
|
- !ruby/object:Gem::Version
|
168
|
-
version: '
|
169
|
+
version: '3.1'
|
169
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
171
|
requirements:
|
171
172
|
- - ">="
|
172
173
|
- !ruby/object:Gem::Version
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
+
rubygems_version: 3.3.27
|
176
177
|
signing_key:
|
177
178
|
specification_version: 4
|
178
179
|
summary: Ensure your Puppet manifests conform with the Puppetlabs style guide
|
@@ -1,51 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
'%{test}' % { test: 'replaced' } == 'replaced'
|
3
|
-
rescue StandardError
|
4
|
-
# monkeypatch String#% into Ruby 1.8.7
|
5
|
-
class String
|
6
|
-
Percent = instance_method(:%) unless defined?(Percent)
|
7
|
-
|
8
|
-
def %(*a, &b)
|
9
|
-
a.flatten!
|
10
|
-
|
11
|
-
string = case a.last
|
12
|
-
when Hash
|
13
|
-
expand(a.pop)
|
14
|
-
else
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
if a.empty?
|
19
|
-
string
|
20
|
-
else
|
21
|
-
Percent.bind_call(string, a, &b)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def expand!(vars = {})
|
26
|
-
loop do
|
27
|
-
changed = false
|
28
|
-
vars.each do |var, value|
|
29
|
-
var = var.to_s
|
30
|
-
var.gsub!(%r{[^a-zA-Z0-9_]}, '')
|
31
|
-
changed = gsub!(%r{%\{#{var}\}}, value.to_s)
|
32
|
-
end
|
33
|
-
break unless changed
|
34
|
-
end
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
def expand(opts = {})
|
39
|
-
dup.expand!(opts)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
unless String.respond_to?(:prepend)
|
45
|
-
# monkeypatch String#prepend into Ruby 1.8.7
|
46
|
-
class String
|
47
|
-
def prepend(lead)
|
48
|
-
replace("#{lead}#{self}")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|