puppet-lint 4.2.0 → 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -4
- data/lib/puppet-lint/data.rb +110 -61
- data/lib/puppet-lint/lexer.rb +2 -2
- data/lib/puppet-lint/plugins/check_whitespace/line_length.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 +4 -4
- data/lib/puppet-lint/version.rb +1 -1
- data/rubocop_baseline.yml +7 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/puppet-lint/checks_spec.rb +7 -2
- data/spec/unit/puppet-lint/ignore_overrides_spec.rb +6 -6
- data/spec/unit/puppet-lint/lexer_spec.rb +702 -699
- data/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +5 -5
- data/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +8 -8
- data/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +2 -1
- data/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
- data/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +3 -3
- data/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +3 -3
- data/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +5 -5
- data/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +14 -14
- data/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb +21 -21
- data/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb +4 -4
- data/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +6 -6
- data/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb +5 -5
- data/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +11 -11
- data/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +6 -6
- data/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +12 -12
- data/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +4 -4
- data/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb +22 -22
- data/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +8 -8
- data/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +13 -13
- data/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +18 -18
- data/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +6 -6
- data/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +4 -4
- data/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +8 -8
- data/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +3 -3
- data/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +7 -7
- data/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +5 -5
- data/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb +4 -4
- data/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +1 -1
- data/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +4 -4
- data/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +37 -37
- data/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +6 -6
- data/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +83 -75
- data/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +19 -19
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e762e8a97a52868c81c71f50b4a168b2ffe6057019d7bae74de03c7c5b2e39ff
|
4
|
+
data.tar.gz: 29f70f084a46c9e218b33447cc0b5573b0c1a7a6d451e7a051977906a83de0cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 298c4387c06213f7ecaf8a84b4367762d1efbbf7752b33f09b4b6064d62a1e567b467bbdf91e6c9009c1052f78c6b2bf7570fc2c7efba454a961ffc386c3ffda
|
7
|
+
data.tar.gz: e8425d0f5b5f1c0ab14d7b9dc8de13bfefd4e57b5209839f2523a1b3701e807182f5c41c2d99a04bc18e74bbf0507eda8eb495ee550521fa3cfe9f5d89a406fe
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# Puppet Lint
|
2
2
|
|
3
|
+
[![Code Owners](https://img.shields.io/badge/owners-DevX--team-blue)](https://github.com/puppetlabs/puppet-lint/blob/main/CODEOWNERS)
|
4
|
+
![ci](https://github.com/puppetlabs/puppet-lint/actions/workflows/ci.yml/badge.svg)
|
5
|
+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/puppetlabs/puppet-lint)
|
6
|
+
|
3
7
|
Puppet Lint tests Puppet code against the recommended [Puppet language style
|
4
8
|
guide](http://puppet.com/docs/puppet/latest/style_guide.html). Puppet Lint validates only code style; it does not validate syntax. To test syntax, use Puppet's `puppet parser validate` command.
|
5
9
|
|
6
10
|
## Compatibility warning
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
In cases where Puppet Lint is required in an environment with Puppet 6, we recommend pinning to version 2.5.2.
|
12
|
+
This tool is only supported on Puppet 7 & 8 environments. In cases where Puppet Lint is required in an environment with Puppet 6, we recommend pinning to version 2.5.2.
|
11
13
|
|
12
14
|
## Installation
|
13
15
|
|
@@ -112,7 +114,7 @@ Any flag that can be specified on the command line can also be specified in the
|
|
112
114
|
--no-hard_tabs-check
|
113
115
|
```
|
114
116
|
|
115
|
-
Or to specify
|
117
|
+
Or to specify an allowlist of allowed checks, include a line like:
|
116
118
|
|
117
119
|
```
|
118
120
|
--only-checks=trailing_whitespace,hard_tabs,duplicate_params,double_quoted_strings,unquoted_file_mode,only_variable_string,variables_not_enclosed,single_quote_string_with_variables,variable_contains_dash,ensure_not_symlink_target,unquoted_resource_title,relative_classname_inclusion,file_mode,resource_reference_without_title_capital,leading_zero,arrow_alignment,variable_is_lowercase,ensure_first_param,resource_reference_without_whitespace,file_ensure,trailing_comma,leading_zero
|
@@ -293,6 +295,18 @@ If you find a bug in Puppet Lint or its results, please create an issue in the
|
|
293
295
|
[repo issues tracker](https://github.com/puppetlabs/puppet-lint/issues/). Bonus
|
294
296
|
points will be awarded if you also include a patch that fixes the issue.
|
295
297
|
|
298
|
+
## Development
|
299
|
+
|
300
|
+
Acceptance tests for this tool leverage [puppet_litmus](https://github.com/puppetlabs/puppet_litmus).
|
301
|
+
To run the acceptance tests follow the instructions [here](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#install-the-necessary-gems-for-the-module).
|
302
|
+
You can also find a tutorial and walkthrough of using Litmus and the PDK on [YouTube](https://www.youtube.com/watch?v=FYfR7ZEGHoE).
|
303
|
+
|
304
|
+
If you run into an issue with this tool or would like to request a feature you can [raise a PR](https://github.com/puppetlabs/puppet-lint/pulls) with your suggested changes. Alternatively, you can [raise a Github issue](https://github.com/puppetlabs/puppet-lint/issues) with a feature request or to report any bugs.
|
305
|
+
Every other Tuesday the DevX team holds [office hours](https://puppet.com/community/office-hours) in the [Puppet Community Slack](http://slack.puppet.com/), where you can ask questions about this and any other supported tools.
|
306
|
+
This session runs at 15:00 (GMT) for about an hour.
|
307
|
+
|
308
|
+
If you have problems getting this tool up and running, please [contact Support](http://puppetlabs.com/services/customer-support).
|
309
|
+
|
296
310
|
## Thank you
|
297
311
|
|
298
312
|
Many thanks to the following people for contributing to puppet-lint
|
data/lib/puppet-lint/data.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
-
#
|
5
|
-
#
|
4
|
+
# A singleton class storing all the information about the manifest being
|
5
|
+
# analysed.
|
6
|
+
#
|
7
|
+
# @api public
|
6
8
|
class PuppetLint::Data
|
7
9
|
include Singleton
|
8
10
|
|
9
11
|
class << self
|
10
|
-
#
|
11
|
-
#
|
12
|
+
# Get/Set the full expanded path to the manifest file being checked.
|
13
|
+
#
|
14
|
+
# @api private
|
12
15
|
attr_reader :path, :fullpath, :filename
|
13
16
|
|
14
|
-
#
|
17
|
+
# Get/Set the raw manifest data, split by \n.
|
18
|
+
#
|
19
|
+
# @api private
|
15
20
|
attr_accessor :manifest_lines
|
16
21
|
|
17
|
-
#
|
22
|
+
# Store the tokenised manifest.
|
18
23
|
#
|
19
|
-
# tokens
|
24
|
+
# @param [Array[PuppetLint::Lexer::Token]] tokens The Array of PuppetLint::Lexer::Token objects to store.
|
25
|
+
# @return [nil]
|
20
26
|
#
|
21
|
-
#
|
27
|
+
# @api private
|
22
28
|
def tokens=(tokens)
|
23
29
|
@tokens = tokens
|
24
30
|
@title_tokens = nil
|
@@ -32,14 +38,17 @@ class PuppetLint::Data
|
|
32
38
|
@defaults_indexes = nil
|
33
39
|
end
|
34
40
|
|
41
|
+
# @api private
|
35
42
|
def ruby1?
|
36
43
|
@ruby1 = RbConfig::CONFIG['MAJOR'] == '1' if @ruby1.nil?
|
37
44
|
@ruby1
|
38
45
|
end
|
39
46
|
|
40
|
-
#
|
47
|
+
# Get the tokenised manifest.
|
48
|
+
#
|
49
|
+
# @return [Array[PuppetLint::Lexer::Token]]
|
41
50
|
#
|
42
|
-
#
|
51
|
+
# @api public
|
43
52
|
def tokens
|
44
53
|
calling_method = if ruby1?
|
45
54
|
begin
|
@@ -62,7 +71,12 @@ class PuppetLint::Data
|
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
65
|
-
#
|
74
|
+
# Add new token.
|
75
|
+
#
|
76
|
+
# @param [Integer] index
|
77
|
+
# @param [PuppetLint::Lexer::Token] token
|
78
|
+
#
|
79
|
+
# @api public
|
66
80
|
def insert(index, token)
|
67
81
|
current_token = tokens[index - 1]
|
68
82
|
token.next_token = current_token.next_token
|
@@ -97,7 +111,11 @@ class PuppetLint::Data
|
|
97
111
|
tokens.insert(index, token)
|
98
112
|
end
|
99
113
|
|
100
|
-
#
|
114
|
+
# Remove a token
|
115
|
+
#
|
116
|
+
# @param [PuppetLint::Lexer::Token] token
|
117
|
+
#
|
118
|
+
# @api public
|
101
119
|
def delete(token)
|
102
120
|
token.next_token.prev_token = token.prev_token unless token.next_token.nil?
|
103
121
|
token.prev_token.next_token = token.next_token unless token.prev_token.nil?
|
@@ -109,12 +127,13 @@ class PuppetLint::Data
|
|
109
127
|
tokens.delete(token)
|
110
128
|
end
|
111
129
|
|
112
|
-
#
|
113
|
-
# filename.
|
130
|
+
# Store the path to the manifest file and populate fullpath and filename.
|
114
131
|
#
|
115
|
-
# val
|
132
|
+
# @param [String] val The path to the file
|
116
133
|
#
|
117
|
-
#
|
134
|
+
# @return [nil]
|
135
|
+
#
|
136
|
+
# @api private
|
118
137
|
def path=(val)
|
119
138
|
@path = val
|
120
139
|
if val.nil?
|
@@ -126,9 +145,11 @@ class PuppetLint::Data
|
|
126
145
|
end
|
127
146
|
end
|
128
147
|
|
129
|
-
#
|
148
|
+
# Retrieve a list of tokens that represent resource titles
|
149
|
+
#
|
150
|
+
# @return [Array[PuppetLint::Lexer::Token]]
|
130
151
|
#
|
131
|
-
#
|
152
|
+
# @api private
|
132
153
|
def title_tokens
|
133
154
|
@title_tokens ||= begin
|
134
155
|
result = []
|
@@ -153,10 +174,11 @@ class PuppetLint::Data
|
|
153
174
|
end
|
154
175
|
end
|
155
176
|
|
156
|
-
#
|
157
|
-
# the token chain..
|
177
|
+
# Determine if the given token contains a CLASSREF in the token chain..
|
158
178
|
#
|
159
|
-
#
|
179
|
+
# @param [PuppetLint::Lexer::Token] token
|
180
|
+
#
|
181
|
+
# @api private
|
160
182
|
def classref?(token)
|
161
183
|
current_token = token
|
162
184
|
while (current_token = current_token.prev_code_token)
|
@@ -165,15 +187,15 @@ class PuppetLint::Data
|
|
165
187
|
end
|
166
188
|
end
|
167
189
|
|
168
|
-
#
|
190
|
+
# Calculate the positions of all resource declarations within the
|
169
191
|
# tokenised manifest. These positions only point to the content of the
|
170
192
|
# resource declarations, they do not include resource types or titles.
|
171
193
|
#
|
172
|
-
#
|
173
|
-
# :
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
194
|
+
# @return [Array[Hash[Symbol, Integer]]] each hash contains :start and
|
195
|
+
# :end pointing to the first and last {PuppetLint::Lexer::Token} of a
|
196
|
+
# resource declaration
|
197
|
+
#
|
198
|
+
# @api private
|
177
199
|
def resource_indexes
|
178
200
|
@resource_indexes ||= begin
|
179
201
|
marker = 0
|
@@ -204,12 +226,15 @@ class PuppetLint::Data
|
|
204
226
|
end
|
205
227
|
end
|
206
228
|
|
207
|
-
#
|
229
|
+
# Find the Token representing the type of a resource definition.
|
230
|
+
#
|
231
|
+
# @param [Integer] index
|
232
|
+
# The Integer pointing to the start of the resource in the `tokens`
|
233
|
+
# array.
|
208
234
|
#
|
209
|
-
#
|
210
|
-
# array.
|
235
|
+
# @return [PuppetLint::Lexer::Token]
|
211
236
|
#
|
212
|
-
#
|
237
|
+
# @api private
|
213
238
|
def find_resource_type_token(index)
|
214
239
|
lbrace_idx = tokens[0..index].rindex do |token|
|
215
240
|
token.type == :LBRACE && token.prev_code_token.type != :QMARK
|
@@ -220,13 +245,15 @@ class PuppetLint::Data
|
|
220
245
|
tokens[lbrace_idx].prev_code_token
|
221
246
|
end
|
222
247
|
|
223
|
-
#
|
248
|
+
# Find all the Token objects representing the parameter names in
|
224
249
|
# a resource definition.
|
225
250
|
#
|
226
|
-
#
|
227
|
-
#
|
251
|
+
# @param [Array[PuppetLint::Lexer::Token]] resource_tokens
|
252
|
+
# An Array of Token objects that comprise the resource definition.
|
228
253
|
#
|
229
|
-
#
|
254
|
+
# @return [Array[PuppetLint::Lexer::Token]]
|
255
|
+
#
|
256
|
+
# @api private
|
230
257
|
def find_resource_param_tokens(resource_tokens)
|
231
258
|
param_tokens = []
|
232
259
|
|
@@ -243,8 +270,8 @@ class PuppetLint::Data
|
|
243
270
|
param_tokens
|
244
271
|
end
|
245
272
|
|
246
|
-
#
|
247
|
-
#
|
273
|
+
# Calculate the positions of all class definitions within the `tokens`
|
274
|
+
# Array.
|
248
275
|
#
|
249
276
|
# Returns an Array of Hashes, each containing:
|
250
277
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -253,12 +280,14 @@ class PuppetLint::Data
|
|
253
280
|
# Token of a class definition.
|
254
281
|
# :tokens - An Array consisting of all the Token objects that make up the
|
255
282
|
# class definition.
|
283
|
+
#
|
284
|
+
# @api private
|
256
285
|
def class_indexes
|
257
286
|
@class_indexes ||= definition_indexes(:CLASS)
|
258
287
|
end
|
259
288
|
|
260
|
-
#
|
261
|
-
#
|
289
|
+
# Calculate the positions of all defined type definitions within the
|
290
|
+
# `tokens` Array.
|
262
291
|
#
|
263
292
|
# Returns an Array of Hashes, each containing:
|
264
293
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -267,12 +296,14 @@ class PuppetLint::Data
|
|
267
296
|
# Token of a defined type definition.
|
268
297
|
# :tokens - An Array consisting of all the Token objects that make up the
|
269
298
|
# defined type.
|
299
|
+
#
|
300
|
+
# @api private
|
270
301
|
def defined_type_indexes
|
271
302
|
@defined_type_indexes ||= definition_indexes(:DEFINE)
|
272
303
|
end
|
273
304
|
|
274
|
-
#
|
275
|
-
#
|
305
|
+
# Calculate the positions of all node definitions within the `tokens`
|
306
|
+
# Array.
|
276
307
|
#
|
277
308
|
# Returns an Array of Hashes, each containing:
|
278
309
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -281,12 +312,14 @@ class PuppetLint::Data
|
|
281
312
|
# Token of a defined type definition.
|
282
313
|
# :tokens - An Array consisting of all the Token objects that make up the
|
283
314
|
# defined type.
|
315
|
+
#
|
316
|
+
# @api private
|
284
317
|
def node_indexes
|
285
318
|
@node_indexes ||= definition_indexes(:NODE)
|
286
319
|
end
|
287
320
|
|
288
|
-
#
|
289
|
-
#
|
321
|
+
# Calculate the positions of all the specified defintion types within the
|
322
|
+
# `tokens` Array.
|
290
323
|
#
|
291
324
|
# Returns an Array of Hashes, each containing:
|
292
325
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -295,6 +328,8 @@ class PuppetLint::Data
|
|
295
328
|
# Token of a definition.
|
296
329
|
# :tokens - An Array consisting of all the Token objects that make up the
|
297
330
|
# definition.
|
331
|
+
#
|
332
|
+
# @api private
|
298
333
|
def definition_indexes(type)
|
299
334
|
result = []
|
300
335
|
tokens.each_with_index do |token, i|
|
@@ -336,8 +371,7 @@ class PuppetLint::Data
|
|
336
371
|
result
|
337
372
|
end
|
338
373
|
|
339
|
-
#
|
340
|
-
# `tokens` Array.
|
374
|
+
# Calculate the positions of all function calls within `tokens` Array.
|
341
375
|
#
|
342
376
|
# Returns an Array of Hashes, each containing:
|
343
377
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -346,6 +380,8 @@ class PuppetLint::Data
|
|
346
380
|
# Token of a function call
|
347
381
|
# :tokens - An Array consisting of all the Token objects that make up the
|
348
382
|
# function call.
|
383
|
+
#
|
384
|
+
# @api private
|
349
385
|
def function_indexes
|
350
386
|
@function_indexes ||= begin
|
351
387
|
functions = []
|
@@ -385,8 +421,7 @@ class PuppetLint::Data
|
|
385
421
|
end
|
386
422
|
end
|
387
423
|
|
388
|
-
#
|
389
|
-
# `tokens` Array.
|
424
|
+
# Calculate the positions of all array values within `tokens` Array.
|
390
425
|
#
|
391
426
|
# Returns an Array of Hashes, each containing:
|
392
427
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -395,6 +430,8 @@ class PuppetLint::Data
|
|
395
430
|
# Token of an array value
|
396
431
|
# :tokens - An Array consisting of all the Token objects that make up the
|
397
432
|
# array value.
|
433
|
+
#
|
434
|
+
# @api private
|
398
435
|
def array_indexes
|
399
436
|
@array_indexes ||= begin
|
400
437
|
arrays = []
|
@@ -421,8 +458,7 @@ class PuppetLint::Data
|
|
421
458
|
end
|
422
459
|
end
|
423
460
|
|
424
|
-
#
|
425
|
-
# `tokens` Array.
|
461
|
+
# Calculate the positions of all hash values within `tokens` Array.
|
426
462
|
#
|
427
463
|
# Returns an Array of Hashes, each containing:
|
428
464
|
# :start - An Integer position in the `tokens` Array pointing to the
|
@@ -431,6 +467,8 @@ class PuppetLint::Data
|
|
431
467
|
# Token of an hash value
|
432
468
|
# :tokens - An Array consisting of all the Token objects that make up the
|
433
469
|
# hash value.
|
470
|
+
#
|
471
|
+
# @api private
|
434
472
|
def hash_indexes
|
435
473
|
@hash_indexes ||= begin
|
436
474
|
hashes = []
|
@@ -459,7 +497,7 @@ class PuppetLint::Data
|
|
459
497
|
end
|
460
498
|
end
|
461
499
|
|
462
|
-
#
|
500
|
+
# Calculate the positions of all defaults declarations within
|
463
501
|
# `tokens` Array.
|
464
502
|
#
|
465
503
|
# Returns an Array of Hashes, each containing:
|
@@ -469,6 +507,8 @@ class PuppetLint::Data
|
|
469
507
|
# Token of the defaults declaration
|
470
508
|
# :tokens - An Array consisting of all the Token objects that make up the
|
471
509
|
# defaults declaration.
|
510
|
+
#
|
511
|
+
# @api private
|
472
512
|
def defaults_indexes
|
473
513
|
@defaults_indexes ||= begin
|
474
514
|
defaults = []
|
@@ -493,14 +533,17 @@ class PuppetLint::Data
|
|
493
533
|
end
|
494
534
|
end
|
495
535
|
|
496
|
-
#
|
536
|
+
# Finds all the tokens that make up the defined type or class
|
497
537
|
# definition parameters.
|
498
538
|
#
|
499
|
-
#
|
500
|
-
#
|
539
|
+
# @param [Array[PuppetLint::Lexer::Token]] these_tokens
|
540
|
+
# An Array of PuppetLint::Lexer::Token objects that make up the defined
|
541
|
+
# type or class definition.
|
501
542
|
#
|
502
|
-
#
|
503
|
-
#
|
543
|
+
# @return [Array[PuppetLint::Lexer::Token], nil] objects or nil if it takes
|
544
|
+
# no parameters.
|
545
|
+
#
|
546
|
+
# @api private
|
504
547
|
def param_tokens(these_tokens)
|
505
548
|
depth = 0
|
506
549
|
lparen_idx = nil
|
@@ -529,28 +572,34 @@ class PuppetLint::Data
|
|
529
572
|
end
|
530
573
|
end
|
531
574
|
|
532
|
-
#
|
575
|
+
# Retrieves a list of token types that are considered to be
|
533
576
|
# formatting tokens (whitespace, newlines, etc).
|
534
577
|
#
|
535
|
-
#
|
578
|
+
# @return [Array[Symbol]]
|
579
|
+
#
|
580
|
+
# @api private
|
536
581
|
def formatting_tokens
|
537
582
|
@formatting_tokens ||= PuppetLint::Lexer::FORMATTING_TOKENS
|
538
583
|
end
|
539
584
|
|
540
|
-
#
|
585
|
+
# Retrieves a Hash of Sets. Each key is a check name Symbol and
|
541
586
|
# the Set of Integers returned lists all the lines that the check results
|
542
587
|
# should be ignored on.
|
543
588
|
#
|
544
|
-
#
|
589
|
+
# @return [Hash[Symbol, Set[Integer]]]
|
590
|
+
#
|
591
|
+
# @api private
|
545
592
|
def ignore_overrides
|
546
593
|
@ignore_overrides ||= {}
|
547
594
|
end
|
548
595
|
|
549
|
-
#
|
596
|
+
# Parses all COMMENT, MLCOMMENT and SLASH_COMMENT tokens looking
|
550
597
|
# for control comments (comments that enable or disable checks). Builds the
|
551
598
|
# contents of the `ignore_overrides` hash.
|
552
599
|
#
|
553
|
-
#
|
600
|
+
# @return [nil]
|
601
|
+
#
|
602
|
+
# @api private
|
554
603
|
def parse_control_comments
|
555
604
|
@ignore_overrides.each_key { |check| @ignore_overrides[check].clear }
|
556
605
|
|
data/lib/puppet-lint/lexer.rb
CHANGED
@@ -50,7 +50,7 @@ class PuppetLint::Lexer
|
|
50
50
|
|
51
51
|
# Internal: A Hash whose keys are Strings representing reserved keywords in
|
52
52
|
# the Puppet DSL.
|
53
|
-
# From https://github.com/puppetlabs/puppet/blob/
|
53
|
+
# From https://github.com/puppetlabs/puppet/blob/main/lib/puppet/pops/parser/lexer2.rb#L116-L137
|
54
54
|
# or thereabouts
|
55
55
|
KEYWORDS = {
|
56
56
|
'case' => true,
|
@@ -78,7 +78,7 @@ class PuppetLint::Lexer
|
|
78
78
|
|
79
79
|
# Internal: A Hash whose keys are Strings representing reserved keywords in
|
80
80
|
# the Puppet DSL when Application Management is enabled
|
81
|
-
# From https://github.com/puppetlabs/puppet/blob/
|
81
|
+
# From https://github.com/puppetlabs/puppet/blob/main/lib/puppet/pops/parser/lexer2.rb#L142-L159
|
82
82
|
# or therabouts
|
83
83
|
# Currently unused
|
84
84
|
APP_MANAGEMENT_TOKENS = {
|
@@ -9,7 +9,7 @@ class PuppetLint::LineLengthCheck
|
|
9
9
|
# @param content [String] The content of the current line.
|
10
10
|
# @param character_count [Integer] The maximum number of characters allowed
|
11
11
|
#
|
12
|
-
# @return
|
12
|
+
# @return [Array] An array containing a description of the problem.
|
13
13
|
# Can be passed directly to notify..
|
14
14
|
def self.check(line_number, content, character_count)
|
15
15
|
return if content.include? '://'
|
@@ -116,8 +116,8 @@ PuppetLint.new_check(:legacy_facts) do
|
|
116
116
|
fact_name = ''
|
117
117
|
|
118
118
|
# This matches legacy facts defined in the fact hash.
|
119
|
-
if (match =
|
120
|
-
fact_name = match[
|
119
|
+
if (match = token.value.match(%r{^(?:::)?facts\[(?<quote>'?)(?<value>.+)\k<quote>\]$}))
|
120
|
+
fact_name = match[:value]
|
121
121
|
|
122
122
|
# This matches using legacy facts in a the new structured fact. For
|
123
123
|
# example this would match 'uuid' in $facts['uuid'] so it can be converted
|
@@ -7,7 +7,7 @@
|
|
7
7
|
# If you have top scope variables that aren't facts you should configure the
|
8
8
|
# linter to ignore them.
|
9
9
|
#
|
10
|
-
# You can
|
10
|
+
# You can allowlist top scope variables to ignore via the Rake task.
|
11
11
|
# You should insert the following line to your Rakefile.
|
12
12
|
# `PuppetLint.configuration.top_scope_variables = ['location', 'role']`
|
13
13
|
#
|
@@ -17,7 +17,7 @@ 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
|
-
|
20
|
+
allowlist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version',
|
21
21
|
'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain',
|
22
22
|
'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename',
|
23
23
|
'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease',
|
@@ -28,10 +28,10 @@ PuppetLint.new_check(:top_scope_facts) do
|
|
28
28
|
'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber',
|
29
29
|
'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds',
|
30
30
|
'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || [])
|
31
|
-
|
31
|
+
allowlist = allowlist.join('|')
|
32
32
|
tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
|
33
33
|
next unless %r{^::}.match?(token.value)
|
34
|
-
next if %r{^::(#{
|
34
|
+
next if %r{^::(#{allowlist})\[?}.match?(token.value)
|
35
35
|
next if %r{^::[a-z0-9_][a-zA-Z0-9_]+::}.match?(token.value)
|
36
36
|
|
37
37
|
notify :warning, {
|
data/lib/puppet-lint/version.rb
CHANGED
data/rubocop_baseline.yml
CHANGED
@@ -81,3 +81,10 @@ Style/Documentation:
|
|
81
81
|
- spec/**/*
|
82
82
|
Style/WordArray:
|
83
83
|
EnforcedStyle: brackets
|
84
|
+
####################################################
|
85
|
+
# Cops below here due for deprecation
|
86
|
+
####################################################
|
87
|
+
# ``Rspec/FilePath`` is going to be deprecated in the next major release of rubocop >=3.0.0: see <https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath>
|
88
|
+
# As the new cops are already present, e.g., Rspec/SpecFilePathPathFormat, then disabling this in preparation
|
89
|
+
RSpec/FilePath:
|
90
|
+
Enabled: false
|
data/spec/spec_helper.rb
CHANGED
@@ -31,7 +31,7 @@ describe PuppetLint::Checks do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'creates a syntax error problem for the file' do
|
34
|
-
expect(instance.problems).to
|
34
|
+
expect(instance.problems.size).to eq(1)
|
35
35
|
expect(instance.problems.first).to include(
|
36
36
|
kind: :error,
|
37
37
|
check: :syntax,
|
@@ -53,7 +53,7 @@ describe PuppetLint::Checks do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'creates a syntax error problem for the file' do
|
56
|
-
expect(instance.problems).to
|
56
|
+
expect(instance.problems.size).to eq(1)
|
57
57
|
expect(instance.problems.first).to include(
|
58
58
|
kind: :error,
|
59
59
|
check: :syntax,
|
@@ -148,9 +148,14 @@ describe PuppetLint::Checks do
|
|
148
148
|
|
149
149
|
it 'prints out information about the puppet-lint version and ruby environment' do
|
150
150
|
expected_info = [
|
151
|
+
'Whoops! It looks like puppet-lint has encountered an error that it doesn\'t',
|
152
|
+
'know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint',
|
153
|
+
'and paste the following output into the issue description.',
|
154
|
+
'---',
|
151
155
|
"puppet-lint version: #{PuppetLint::VERSION}",
|
152
156
|
"ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
|
153
157
|
"platform: #{RUBY_PLATFORM}",
|
158
|
+
"file path: #{fileinfo}",
|
154
159
|
]
|
155
160
|
pattern = expected_info.map { |r| Regexp.escape(r) }.join('\s+')
|
156
161
|
expect($stdout).to receive(:puts).with(a_string_matching(%r{#{pattern}}m))
|
@@ -13,7 +13,7 @@ describe 'quoted_booleans', type: :lint do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'detects three problems' do
|
16
|
-
expect(problems).to
|
16
|
+
expect(problems.size).to eq(3)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'has two warnings' do
|
@@ -36,7 +36,7 @@ describe 'quoted_booleans', type: :lint do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'detects three problems' do
|
39
|
-
expect(problems).to
|
39
|
+
expect(problems.size).to eq(3)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'has two warnings' do
|
@@ -62,7 +62,7 @@ describe 'quoted_booleans', type: :lint do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'detects four problems' do
|
65
|
-
expect(problems).to
|
65
|
+
expect(problems.size).to eq(4)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'has two warnings' do
|
@@ -89,7 +89,7 @@ describe 'quoted_booleans', type: :lint do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'detects four problems' do
|
92
|
-
expect(problems).to
|
92
|
+
expect(problems.size).to eq(4)
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'has two warnings' do
|
@@ -107,7 +107,7 @@ describe 'quoted_booleans', type: :lint do
|
|
107
107
|
let(:code) { '"true" # lint:ignore:quoted_booleans lint:ignore:double_quoted_string a reason' }
|
108
108
|
|
109
109
|
it 'detects 1 problems' do
|
110
|
-
expect(problems).to
|
110
|
+
expect(problems.size).to eq(1)
|
111
111
|
end
|
112
112
|
|
113
113
|
it 'has one ignored problems' do
|
@@ -129,7 +129,7 @@ describe 'quoted_booleans', type: :lint do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'detects 2 problems' do
|
132
|
-
expect(problems).to
|
132
|
+
expect(problems.size).to eq(2)
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'ignores both problems' do
|