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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -4
  3. data/lib/puppet-lint/data.rb +110 -61
  4. data/lib/puppet-lint/lexer.rb +2 -2
  5. data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +1 -1
  6. data/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +2 -2
  7. data/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +4 -4
  8. data/lib/puppet-lint/version.rb +1 -1
  9. data/rubocop_baseline.yml +7 -0
  10. data/spec/spec_helper.rb +0 -1
  11. data/spec/unit/puppet-lint/checks_spec.rb +7 -2
  12. data/spec/unit/puppet-lint/ignore_overrides_spec.rb +6 -6
  13. data/spec/unit/puppet-lint/lexer_spec.rb +702 -699
  14. data/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +5 -5
  15. data/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +8 -8
  16. data/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +2 -2
  17. data/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +2 -1
  18. data/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
  19. data/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +3 -3
  20. data/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +3 -3
  21. data/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +5 -5
  22. data/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +14 -14
  23. data/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
  24. data/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb +21 -21
  25. data/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
  26. data/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb +4 -4
  27. data/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +6 -6
  28. data/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +2 -2
  29. data/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb +5 -5
  30. data/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +11 -11
  31. data/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +6 -6
  32. data/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +12 -12
  33. data/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +4 -4
  34. data/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb +22 -22
  35. data/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +8 -8
  36. data/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +13 -13
  37. data/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +18 -18
  38. data/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +6 -6
  39. data/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +4 -4
  40. data/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +8 -8
  41. data/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +3 -3
  42. data/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +7 -7
  43. data/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +2 -2
  44. data/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +5 -5
  45. data/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb +4 -4
  46. data/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +1 -1
  47. data/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +4 -4
  48. data/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +37 -37
  49. data/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +2 -2
  50. data/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +6 -6
  51. data/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +83 -75
  52. data/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +19 -19
  53. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69069ebb59ecc423674d2918bf4493ae0da816b8d9a6f3da7db8a34cc7e657bf
4
- data.tar.gz: 28cfb8db332d53efcaab17e412a1f965a382a341aa3696c2148116ce18b4570b
3
+ metadata.gz: e762e8a97a52868c81c71f50b4a168b2ffe6057019d7bae74de03c7c5b2e39ff
4
+ data.tar.gz: 29f70f084a46c9e218b33447cc0b5573b0c1a7a6d451e7a051977906a83de0cc
5
5
  SHA512:
6
- metadata.gz: 3f951b0291881ea53286adf57085a8cc0ef5164028ca2c815b05bd196f4f35f038d10910fb417d03465590ba0af20a835fceaa1037808f5a697d8c1ce0ce3b76
7
- data.tar.gz: 4c6347b7c83ab801cc03994c4422239ebec41ce851179f4362c43b0aa012f61ea362aebc27b0a8da5abd3c42fea1274d10c97092782f24635d95eb9b96612b03
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
- Version 3.0.0 and above will no longer support Puppet 6 environments.
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 a whitelist of allowed checks, include a line like:
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
@@ -1,24 +1,30 @@
1
1
  require 'singleton'
2
2
  require 'set'
3
3
 
4
- # Public: A singleton class storing all the information about the manifest
5
- # being analysed.
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
- # Internal: Get/Set the full expanded path to the manifest file being
11
- # checked.
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
- # Internal: Get/Set the raw manifest data, split by \n.
17
+ # Get/Set the raw manifest data, split by \n.
18
+ #
19
+ # @api private
15
20
  attr_accessor :manifest_lines
16
21
 
17
- # Internal: Store the tokenised manifest.
22
+ # Store the tokenised manifest.
18
23
  #
19
- # tokens - The Array of PuppetLint::Lexer::Token objects to store.
24
+ # @param [Array[PuppetLint::Lexer::Token]] tokens The Array of PuppetLint::Lexer::Token objects to store.
25
+ # @return [nil]
20
26
  #
21
- # Returns nothing.
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
- # Public: Get the tokenised manifest.
47
+ # Get the tokenised manifest.
48
+ #
49
+ # @return [Array[PuppetLint::Lexer::Token]]
41
50
  #
42
- # Returns an Array of PuppetLint::Lexer::Token objects.
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
- # Public: Add new token.
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
- # Public: Removes a token
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
- # Internal: Store the path to the manifest file and populate fullpath and
113
- # filename.
130
+ # Store the path to the manifest file and populate fullpath and filename.
114
131
  #
115
- # val - The path to the file as a String.
132
+ # @param [String] val The path to the file
116
133
  #
117
- # Returns nothing.
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
- # Internal: Retrieve a list of tokens that represent resource titles
148
+ # Retrieve a list of tokens that represent resource titles
149
+ #
150
+ # @return [Array[PuppetLint::Lexer::Token]]
130
151
  #
131
- # Returns an Array of PuppetLint::Lexer::Token objects.
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
- # Internal: Determine if the given token contains a CLASSREF in
157
- # the token chain..
177
+ # Determine if the given token contains a CLASSREF in the token chain..
158
178
  #
159
- # Returns a Boolean.
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
- # Internal: Calculate the positions of all resource declarations within the
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
- # Returns an Array of Hashes, each containing:
173
- # :start - An Integer position in the `tokens` Array pointing to the
174
- # first Token of a resource declaration.
175
- # :end - An Integer position in the `tokens` Array pointing to the last
176
- # Token of a resource declaration.
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
- # Internal: Find the Token representing the type of a resource definition.
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
- # index - The Integer pointing to the start of the resource in the `tokens`
210
- # array.
235
+ # @return [PuppetLint::Lexer::Token]
211
236
  #
212
- # Returns a Token object.
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
- # Internal: Find all the Token objects representing the parameter names in
248
+ # Find all the Token objects representing the parameter names in
224
249
  # a resource definition.
225
250
  #
226
- # resource_tokens - An Array of Token objects that comprise the resource
227
- # definition.
251
+ # @param [Array[PuppetLint::Lexer::Token]] resource_tokens
252
+ # An Array of Token objects that comprise the resource definition.
228
253
  #
229
- # Returns an Array of Token objects.
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
- # Internal: Calculate the positions of all class definitions within the
247
- # `tokens` Array.
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
- # Internal: Calculate the positions of all defined type definitions within
261
- # the `tokens` Array.
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
- # Internal: Calculate the positions of all node definitions within the
275
- # `tokens` Array.
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
- # Internal: Calculate the positions of all the specified defintion types
289
- # within the `tokens` Array.
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
- # Internal: Calculate the positions of all function calls within
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
- # Internal: Calculate the positions of all array values within
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
- # Internal: Calculate the positions of all hash values within
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
- # Internal: Calculate the positions of all defaults declarations within
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
- # Internal: Finds all the tokens that make up the defined type or class
536
+ # Finds all the tokens that make up the defined type or class
497
537
  # definition parameters.
498
538
  #
499
- # these_tokens - An Array of PuppetLint::Lexer::Token objects that make up
500
- # the defined type or class definition.
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
- # Returns an Array of PuppetLint::Lexer::Token objects or nil if it takes
503
- # no parameters.
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
- # Internal: Retrieves a list of token types that are considered to be
575
+ # Retrieves a list of token types that are considered to be
533
576
  # formatting tokens (whitespace, newlines, etc).
534
577
  #
535
- # Returns an Array of Symbols.
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
- # Internal: Retrieves a Hash of Sets. Each key is a check name Symbol and
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
- # Returns a Hash of Sets of Integers.
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
- # Internal: Parses all COMMENT, MLCOMMENT and SLASH_COMMENT tokens looking
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
- # Returns nothing.
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
 
@@ -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/master/lib/puppet/pops/parser/lexer2.rb#L116-L137
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/master/lib/puppet/pops/parser/lexer2.rb#L142-L159
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 problem [Array] An array containing a description of the problem.
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 = (token.value.match(%r{(::)?facts\['(.*)'\]}) || token.value.match(%r{(::)?facts\[(.*)\]})))
120
- fact_name = match[2]
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 whitelist top scope variables to ignore via the Rake task.
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
- whitelist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version',
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
- whitelist = whitelist.join('|')
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{^::(#{whitelist})\[?}.match?(token.value)
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, {
@@ -1,3 +1,3 @@
1
1
  class PuppetLint
2
- VERSION = '4.2.0'.freeze
2
+ VERSION = '4.2.2'.freeze
3
3
  end
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
@@ -12,7 +12,6 @@ end
12
12
 
13
13
  require 'puppet-lint'
14
14
  require 'rspec/its'
15
- require 'rspec/collection_matchers'
16
15
  begin
17
16
  require 'rspec/json_expectations'
18
17
  rescue LoadError, SyntaxError
@@ -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 have(1).problem
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 have(1).problem
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 have(3).problems
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 have(3).problems
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 have(4).problems
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 have(4).problems
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 have(1).problems
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 have(2).problems
132
+ expect(problems.size).to eq(2)
133
133
  end
134
134
 
135
135
  it 'ignores both problems' do