puppet-lint 4.0.0 → 4.0.1
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/lexer/token.rb +1 -1
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +6 -8
- data/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +2 -7
- data/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +11 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/spec/fixtures/test/reports/code_climate.json +1 -1
- data/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +67 -13
- data/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +8 -0
- data/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +3 -47
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c29efe87a1b5506f4849bf91bb2ebdd9aa76985bbfe0cb9206de80d309a5611
|
4
|
+
data.tar.gz: f17c4c2195f16b27e5595c9e1546ae53ad255913f2ea42203a9eee221e11d809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '048132fc797b8f1ac6b31a310db4b4f654f71930847b6839783107381d7d46893d672ad3c879e6792f8f2c5367aa733addb855cd820c2578da63b4222853e13f'
|
7
|
+
data.tar.gz: b9d4f0a474c89731757c336811e910885ce87bd4dca6c4041355f2646e51ad87c38eeaa66ced098aca4146d4c33b03c2bffeb970bd0c91c00d111984cd493718
|
@@ -30,7 +30,7 @@ class PuppetLint::Lexer
|
|
30
30
|
# etc) in the manifest.
|
31
31
|
attr_accessor :next_code_token
|
32
32
|
|
33
|
-
# Public: Gets/sets the previous code
|
33
|
+
# Public: Gets/sets the previous code token (skips whitespace,
|
34
34
|
# comments, etc) in the manifest.
|
35
35
|
attr_accessor :prev_code_token
|
36
36
|
|
@@ -37,7 +37,7 @@ PuppetLint.new_check(:parameter_order) do
|
|
37
37
|
column: token.column,
|
38
38
|
description: 'Test the manifest tokens for any parameterised classes or defined types that take ' \
|
39
39
|
'parameters and record a warning if there are any optional parameters listed before required parameters.',
|
40
|
-
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order
|
40
|
+
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#params-display-order',
|
41
41
|
)
|
42
42
|
end
|
43
43
|
end
|
@@ -48,17 +48,15 @@ PuppetLint.new_check(:parameter_order) do
|
|
48
48
|
return false unless token.prev_code_token
|
49
49
|
|
50
50
|
[
|
51
|
-
:LPAREN,
|
52
|
-
:COMMA,
|
53
|
-
:TYPE,
|
54
|
-
:RBRACK,
|
51
|
+
:LPAREN, # First parameter, no type specification
|
52
|
+
:COMMA, # Subsequent parameter, no type specification
|
53
|
+
:TYPE, # Parameter with simple type specification
|
54
|
+
:RBRACK, # Parameter with complex type specification
|
55
|
+
:CLASSREF, # Parameter with custom type specification
|
55
56
|
].include?(token.prev_code_token.type)
|
56
57
|
end
|
57
58
|
|
58
59
|
def required_parameter?(token)
|
59
|
-
data_type = token.prev_token_of(:TYPE, skip_blocks: true)
|
60
|
-
return false if data_type && data_type.value == 'Optional'
|
61
|
-
|
62
60
|
return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
|
63
61
|
|
64
62
|
false
|
@@ -115,14 +115,9 @@ PuppetLint.new_check(:legacy_facts) do
|
|
115
115
|
tokens.select { |x| LEGACY_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
|
116
116
|
fact_name = ''
|
117
117
|
|
118
|
-
# This matches legacy facts defined in the fact hash that use the top scope
|
119
|
-
# fact assignment.
|
120
|
-
if token.value.start_with?('::facts[')
|
121
|
-
fact_name = token.value.match(%r{::facts\['(.*)'\]})[1]
|
122
|
-
|
123
118
|
# This matches legacy facts defined in the fact hash.
|
124
|
-
|
125
|
-
fact_name =
|
119
|
+
if (match = (token.value.match(%r{(::)?facts\['(.*)'\]}) || token.value.match(%r{(::)?facts\[(.*)\]})))
|
120
|
+
fact_name = match[2]
|
126
121
|
|
127
122
|
# This matches using legacy facts in a the new structured fact. For
|
128
123
|
# example this would match 'uuid' in $facts['uuid'] so it can be converted
|
@@ -17,7 +17,17 @@ TOP_SCOPE_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
|
17
17
|
|
18
18
|
PuppetLint.new_check(:top_scope_facts) do
|
19
19
|
def check
|
20
|
-
whitelist = ['trusted', 'facts'
|
20
|
+
whitelist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version',
|
21
|
+
'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain',
|
22
|
+
'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename',
|
23
|
+
'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease',
|
24
|
+
'macaddress', 'macosx_buildversion', 'macosx_productname', 'macosx_productversion', 'macosx_productversion_major',
|
25
|
+
'macosx_productversion_minor', 'manufacturer', 'memoryfree', 'memorysize', 'netmask', 'netmask6', 'network', 'network6',
|
26
|
+
'operatingsystem', 'operatingsystemmajrelease', 'operatingsystemrelease', 'osfamily', 'physicalprocessorcount',
|
27
|
+
'processorcount', 'productname', 'rubyplatform', 'rubysitedir', 'rubyversion', 'selinux', 'selinux_config_mode',
|
28
|
+
'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber',
|
29
|
+
'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds',
|
30
|
+
'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || [])
|
21
31
|
whitelist = whitelist.join('|')
|
22
32
|
tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
|
23
33
|
next unless %r{^::}.match?(token.value)
|
data/lib/puppet-lint/version.rb
CHANGED
@@ -33,6 +33,6 @@
|
|
33
33
|
}
|
34
34
|
},
|
35
35
|
"fingerprint": "e34cf289e008446b633d1be7cf58120e",
|
36
|
-
"content": "Test the manifest tokens for any parameterised classes or defined types that take parameters and record a warning if there are any optional parameters listed before required parameters. See [this page](https://puppet.com/docs/puppet/latest/style_guide.html#display-order
|
36
|
+
"content": "Test the manifest tokens for any parameterised classes or defined types that take parameters and record a warning if there are any optional parameters listed before required parameters. See [this page](https://puppet.com/docs/puppet/latest/style_guide.html#params-display-order) for more information about the `parameter_order` check."
|
37
37
|
}
|
38
38
|
]
|
@@ -135,19 +135,6 @@ describe 'parameter_order' do
|
|
135
135
|
it { expect(problems).to have(0).problem }
|
136
136
|
end
|
137
137
|
|
138
|
-
context "#{type} parameter with Optional data type" do
|
139
|
-
let(:code) do
|
140
|
-
<<-END
|
141
|
-
#{type} test(
|
142
|
-
String $test = 'value',
|
143
|
-
Optional[String] $optional,
|
144
|
-
) { }
|
145
|
-
END
|
146
|
-
end
|
147
|
-
|
148
|
-
it { expect(problems).to have(0).problems }
|
149
|
-
end
|
150
|
-
|
151
138
|
context "#{type} parameter with array operation" do
|
152
139
|
let(:code) do
|
153
140
|
<<-END
|
@@ -165,5 +152,72 @@ describe 'parameter_order' do
|
|
165
152
|
|
166
153
|
it { expect(problems).to have(0).problems }
|
167
154
|
end
|
155
|
+
|
156
|
+
context "#{type} parameters of Optional type are just regular parameters" do
|
157
|
+
let(:code) do
|
158
|
+
<<-END
|
159
|
+
#{type} test (
|
160
|
+
String $param1 = '',
|
161
|
+
Optional[Boolean] $param2,
|
162
|
+
) { }
|
163
|
+
END
|
164
|
+
end
|
165
|
+
|
166
|
+
it { expect(problems).to have(1).problems }
|
167
|
+
end
|
168
|
+
|
169
|
+
[['Custom::Type1', 'Custom::Type2'], ['Custom::Type1', 'String'], ['String', 'Custom::Type2']].each_with_index do |testtypes, i| # rubocop:disable Performance/CollectionLiteralInLoop
|
170
|
+
context "#{type} parameters of custom type - no values - #{i}" do
|
171
|
+
let(:code) do
|
172
|
+
<<-END
|
173
|
+
#{type} test (
|
174
|
+
#{testtypes[0]} $param1,
|
175
|
+
#{testtypes[0]} $param2,
|
176
|
+
) { }
|
177
|
+
END
|
178
|
+
end
|
179
|
+
|
180
|
+
it { expect(problems).to have(0).problems }
|
181
|
+
end
|
182
|
+
|
183
|
+
context "#{type} parameters of custom type - two values - #{i}" do
|
184
|
+
let(:code) do
|
185
|
+
<<-END
|
186
|
+
#{type} test (
|
187
|
+
#{testtypes[0]} $param1 = 'foo',
|
188
|
+
#{testtypes[1]} $param2 = 'bar',
|
189
|
+
) { }
|
190
|
+
END
|
191
|
+
end
|
192
|
+
|
193
|
+
it { expect(problems).to have(0).problems }
|
194
|
+
end
|
195
|
+
|
196
|
+
context "#{type} parameters of custom type - one value, wrong order - #{i}" do
|
197
|
+
let(:code) do
|
198
|
+
<<-END
|
199
|
+
#{type} test (
|
200
|
+
#{testtypes[0]} $param1 = 'foo',
|
201
|
+
#{testtypes[1]} $param2,
|
202
|
+
) { }
|
203
|
+
END
|
204
|
+
end
|
205
|
+
|
206
|
+
it { expect(problems).to have(1).problems }
|
207
|
+
end
|
208
|
+
|
209
|
+
context "#{type} parameters of custom type - one value, right order - #{i}" do
|
210
|
+
let(:code) do
|
211
|
+
<<-END
|
212
|
+
#{type} test (
|
213
|
+
#{testtypes[0]} $param1,
|
214
|
+
#{testtypes[1]} $param2 = 'bar',
|
215
|
+
) { }
|
216
|
+
END
|
217
|
+
end
|
218
|
+
|
219
|
+
it { expect(problems).to have(0).problems }
|
220
|
+
end
|
221
|
+
end
|
168
222
|
end
|
169
223
|
end
|
@@ -121,6 +121,14 @@ describe 'legacy_facts' do
|
|
121
121
|
expect(problems).to have(1).problem
|
122
122
|
end
|
123
123
|
end
|
124
|
+
|
125
|
+
context 'top scoped fact variable using unquoted legacy facts hash variable in interpolation' do
|
126
|
+
let(:code) { '$::facts[osfamily]' }
|
127
|
+
|
128
|
+
it 'detects a single problem' do
|
129
|
+
expect(problems).to have(1).problem
|
130
|
+
end
|
131
|
+
end
|
124
132
|
end
|
125
133
|
|
126
134
|
context 'with fix enabled' do
|
@@ -37,26 +37,10 @@ describe 'top_scope_facts' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'fact variable using top scope' do
|
40
|
-
let(:code) { '$::
|
40
|
+
let(:code) { '$::fqdn' }
|
41
41
|
|
42
|
-
it '
|
43
|
-
expect(problems).to have(
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'creates a warning' do
|
47
|
-
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'fact variable using top scope with curly braces in double quote' do
|
52
|
-
let(:code) { '"${::operatingsystem}"' }
|
53
|
-
|
54
|
-
it 'onlies detect a single problem' do
|
55
|
-
expect(problems).to have(1).problem
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'creates a warning' do
|
59
|
-
expect(problems).to contain_warning(msg).on_line(1).in_column(4)
|
42
|
+
it 'does not detect a single problem' do
|
43
|
+
expect(problems).to have(0).problem
|
60
44
|
end
|
61
45
|
end
|
62
46
|
|
@@ -126,34 +110,6 @@ describe 'top_scope_facts' do
|
|
126
110
|
end
|
127
111
|
end
|
128
112
|
|
129
|
-
context 'fact variable using top scope' do
|
130
|
-
let(:code) { '$::operatingsystem' }
|
131
|
-
|
132
|
-
it 'onlies detect a single problem' do
|
133
|
-
expect(problems).to have(1).problem
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'fixes the problem' do
|
137
|
-
expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'shoulds use the facts hash' do
|
141
|
-
expect(manifest).to eq("$facts['operatingsystem']")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'fact variable using top scope with curly braces in double quote' do
|
146
|
-
let(:code) { '"${::operatingsystem}"' }
|
147
|
-
|
148
|
-
it 'fixes the problem' do
|
149
|
-
expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'shoulds use the facts hash' do
|
153
|
-
expect(manifest).to eq('"${facts[\'operatingsystem\']}"')
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
113
|
context 'with custom top scope fact variables' do
|
158
114
|
before(:each) do
|
159
115
|
PuppetLint.configuration.top_scope_variables = ['location', 'role']
|
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.0.
|
4
|
+
version: 4.0.1
|
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: 2023-
|
13
|
+
date: 2023-07-31 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"
|