puppet-lint 2.5.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +522 -0
  3. data/lib/puppet-lint/bin.rb +71 -6
  4. data/lib/puppet-lint/checkplugin.rb +43 -9
  5. data/lib/puppet-lint/checks.rb +16 -16
  6. data/lib/puppet-lint/configuration.rb +134 -134
  7. data/lib/puppet-lint/data.rb +28 -28
  8. data/lib/puppet-lint/lexer/string_slurper.rb +138 -140
  9. data/lib/puppet-lint/lexer/token.rb +188 -190
  10. data/lib/puppet-lint/lexer.rb +416 -417
  11. data/lib/puppet-lint/monkeypatches.rb +1 -1
  12. data/lib/puppet-lint/optparser.rb +5 -1
  13. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +6 -4
  14. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +5 -3
  15. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +6 -4
  16. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +5 -3
  17. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +5 -3
  18. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +5 -3
  19. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +7 -5
  20. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -3
  21. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +7 -4
  22. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +5 -3
  23. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +15 -13
  24. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +9 -7
  25. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +10 -8
  26. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +6 -4
  27. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +5 -3
  28. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -3
  29. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +15 -11
  30. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +5 -3
  31. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +8 -5
  32. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +11 -8
  33. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +14 -9
  34. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +11 -6
  35. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +6 -4
  36. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +12 -7
  37. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +8 -6
  38. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +14 -8
  39. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +11 -7
  40. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +11 -6
  41. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +12 -8
  42. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +11 -7
  43. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +11 -7
  44. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +3 -8
  45. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +10 -8
  46. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +3 -8
  47. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +10 -8
  48. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +11 -7
  49. data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +29 -0
  50. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +13 -7
  51. data/lib/puppet-lint/plugins.rb +60 -61
  52. data/lib/puppet-lint/report/github.rb +17 -0
  53. data/lib/puppet-lint/report/sarif_template.json +63 -0
  54. data/lib/puppet-lint/tasks/puppet-lint.rb +84 -83
  55. data/lib/puppet-lint/tasks/release_test.rb +4 -1
  56. data/lib/puppet-lint/version.rb +1 -1
  57. data/lib/puppet-lint.rb +27 -12
  58. data/spec/acceptance/puppet_lint_spec.rb +46 -0
  59. data/spec/spec_helper.rb +92 -91
  60. data/spec/spec_helper_acceptance.rb +6 -0
  61. data/spec/spec_helper_acceptance_local.rb +38 -0
  62. data/spec/{puppet-lint → unit/puppet-lint}/bin_spec.rb +79 -35
  63. data/spec/{puppet-lint → unit/puppet-lint}/checks_spec.rb +36 -36
  64. data/spec/unit/puppet-lint/configuration_spec.rb +88 -0
  65. data/spec/{puppet-lint → unit/puppet-lint}/data_spec.rb +6 -3
  66. data/spec/{puppet-lint → unit/puppet-lint}/ignore_overrides_spec.rb +17 -17
  67. data/spec/{puppet-lint → unit/puppet-lint}/lexer/string_slurper_spec.rb +128 -128
  68. data/spec/{puppet-lint → unit/puppet-lint}/lexer/token_spec.rb +1 -1
  69. data/spec/{puppet-lint → unit/puppet-lint}/lexer_spec.rb +653 -671
  70. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/arrow_on_right_operand_line_spec.rb +16 -16
  71. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/autoloader_layout_spec.rb +13 -13
  72. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/class_inherits_from_params_class_spec.rb +3 -3
  73. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/code_on_top_scope_spec.rb +4 -4
  74. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/inherits_across_namespaces_spec.rb +4 -4
  75. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/name_contains_uppercase_spec.rb +10 -10
  76. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/names_containing_dash_spec.rb +7 -7
  77. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/nested_classes_or_defines_spec.rb +7 -7
  78. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/parameter_order_spec.rb +9 -9
  79. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/right_to_left_relationship_spec.rb +3 -3
  80. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/variable_scope_spec.rb +25 -25
  81. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/slash_comments_spec.rb +7 -7
  82. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/star_comments_spec.rb +13 -13
  83. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/case_without_default_spec.rb +10 -10
  84. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/selector_inside_resource_spec.rb +3 -3
  85. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_documentation/documentation_spec.rb +8 -8
  86. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_nodes/unquoted_node_name_spec.rb +24 -24
  87. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/duplicate_params_spec.rb +9 -9
  88. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_first_param_spec.rb +19 -19
  89. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_not_symlink_target_spec.rb +10 -10
  90. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/file_mode_spec.rb +40 -40
  91. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_file_mode_spec.rb +20 -20
  92. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_resource_title_spec.rb +24 -24
  93. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/double_quoted_strings_spec.rb +27 -27
  94. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/only_variable_string_spec.rb +18 -18
  95. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/puppet_url_without_modules_spec.rb +9 -9
  96. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/quoted_booleans_spec.rb +22 -22
  97. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/single_quote_string_with_variables_spec.rb +2 -2
  98. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/variables_not_enclosed_spec.rb +21 -21
  99. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_contains_dash_spec.rb +6 -6
  100. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_is_lowercase_spec.rb +7 -7
  101. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/140chars_spec.rb +5 -5
  102. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/2sp_soft_tabs_spec.rb +2 -2
  103. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/80chars_spec.rb +6 -6
  104. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/arrow_alignment_spec.rb +127 -127
  105. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/hard_tabs_spec.rb +7 -7
  106. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/trailing_whitespace_spec.rb +15 -15
  107. data/spec/unit/puppet-lint/puppet-lint_spec.rb +18 -0
  108. metadata +63 -119
  109. data/CHANGELOG.md +0 -33
  110. data/HISTORY.md +0 -1130
  111. data/spec/puppet-lint/configuration_spec.rb +0 -66
  112. data/spec/puppet-lint_spec.rb +0 -16
@@ -1,5 +1,5 @@
1
1
  begin
2
- '%{test}' % { :test => 'replaced' } == 'replaced' # rubocop:disable Style/FormatString
2
+ '%{test}' % { test: 'replaced' } == 'replaced'
3
3
  rescue
4
4
  # monkeypatch String#% into Ruby 1.8.7
5
5
  class String
@@ -48,7 +48,7 @@ class PuppetLint::OptParser
48
48
  opts.on(
49
49
  '--error-level LEVEL',
50
50
  [:all, :warning, :error],
51
- 'The level of error to return (warning, error or all).'
51
+ 'The level of error to return (warning, error or all).',
52
52
  ) do |el|
53
53
  PuppetLint.configuration.error_level = el
54
54
  end
@@ -98,6 +98,10 @@ class PuppetLint::OptParser
98
98
  PuppetLint.configuration.json = true
99
99
  end
100
100
 
101
+ opts.on('--sarif', 'Log output as SARIF') do
102
+ PuppetLint.configuration.sarif = true
103
+ end
104
+
101
105
  opts.on('--list-checks', 'List available check names.') do
102
106
  PuppetLint.configuration.list_checks = true
103
107
  end
@@ -9,10 +9,12 @@ PuppetLint.new_check(:arrow_on_right_operand_line) do
9
9
 
10
10
  notify(
11
11
  :warning,
12
- :message => "arrow should be on the right operand's line",
13
- :line => token.line,
14
- :column => token.column,
15
- :token => token
12
+ message: "arrow should be on the right operand's line",
13
+ line: token.line,
14
+ column: token.column,
15
+ token: token,
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
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#chaining-arrow-syntax',
16
18
  )
17
19
  end
18
20
  end
@@ -25,9 +25,11 @@ PuppetLint.new_check(:autoloader_layout) do
25
25
 
26
26
  notify(
27
27
  :error,
28
- :message => "#{title_token.value} not in autoload module layout",
29
- :line => title_token.line,
30
- :column => title_token.column
28
+ message: "#{title_token.value} not in autoload module layout",
29
+ line: title_token.line,
30
+ column: title_token.column,
31
+ description: 'Test the manifest tokens for any classes or defined types that are not in an appropriately named file for the autoloader to detect and record an error of each instance found.',
32
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#separate-files',
31
33
  )
32
34
  end
33
35
  end
@@ -5,13 +5,15 @@
5
5
  PuppetLint.new_check(:class_inherits_from_params_class) do
6
6
  def check
7
7
  class_indexes.each do |class_idx|
8
- next unless class_idx[:inherited_token] && class_idx[:inherited_token].value.end_with?('::params')
8
+ next unless class_idx[:inherited_token] && class_idx[:inherited_token]&.value&.end_with?('::params')
9
9
 
10
10
  notify(
11
11
  :warning,
12
- :message => 'class inheriting from params class',
13
- :line => class_idx[:inherited_token].line,
14
- :column => class_idx[:inherited_token].column
12
+ message: 'class inheriting from params class',
13
+ line: class_idx[:inherited_token].line,
14
+ column: class_idx[:inherited_token].column,
15
+ description: 'Check the manifest tokens for any classes that inherit a params subclass and record a warning for each instance found.',
16
+ help_uri: nil,
15
17
  )
16
18
  end
17
19
  end
@@ -11,9 +11,11 @@ PuppetLint.new_check(:code_on_top_scope) do
11
11
 
12
12
  notify(
13
13
  :warning,
14
- :message => "code outside of class or define block - #{token.value}",
15
- :line => token.line,
16
- :column => token.column
14
+ message: "code outside of class or define block - #{token.value}",
15
+ line: token.line,
16
+ column: token.column,
17
+ description: 'Test that no code is outside of a class or define scope.',
18
+ help_uri: nil,
17
19
  )
18
20
  end
19
21
  end
@@ -14,9 +14,11 @@ PuppetLint.new_check(:inherits_across_namespaces) do
14
14
 
15
15
  notify(
16
16
  :warning,
17
- :message => 'class inherits across module namespaces',
18
- :line => class_idx[:inherited_token].line,
19
- :column => class_idx[:inherited_token].column
17
+ message: 'class inherits across module namespaces',
18
+ line: class_idx[:inherited_token].line,
19
+ column: class_idx[:inherited_token].column,
20
+ description: 'Test the manifest tokens for any classes that inherit across namespaces and record a warning for each instance found.',
21
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#class-inheritance',
20
22
  )
21
23
  end
22
24
  end
@@ -15,9 +15,11 @@ PuppetLint.new_check(:names_containing_dash) do
15
15
 
16
16
  notify(
17
17
  :error,
18
- :message => "#{obj_type} name containing a dash",
19
- :line => class_idx[:name_token].line,
20
- :column => class_idx[:name_token].column
18
+ message: "#{obj_type} name containing a dash",
19
+ line: class_idx[:name_token].line,
20
+ column: class_idx[:name_token].column,
21
+ description: 'Check the manifest tokens for any classes or defined types that have a dash in their name and record an error for each instance found.',
22
+ help_uri: nil,
21
23
  )
22
24
  end
23
25
  end
@@ -5,7 +5,7 @@
5
5
  PuppetLint.new_check(:names_containing_uppercase) do
6
6
  def check
7
7
  (class_indexes + defined_type_indexes).each do |class_idx|
8
- next unless class_idx[:name_token].value =~ %r{[A-Z]}
8
+ next unless %r{[A-Z]}.match?(class_idx[:name_token].value)
9
9
 
10
10
  obj_type = if class_idx[:type] == :CLASS
11
11
  'class'
@@ -15,10 +15,12 @@ PuppetLint.new_check(:names_containing_uppercase) do
15
15
 
16
16
  notify(
17
17
  :error,
18
- :message => "#{obj_type} '#{class_idx[:name_token].value}' contains illegal uppercase",
19
- :line => class_idx[:name_token].line,
20
- :column => class_idx[:name_token].column,
21
- :token => class_idx[:name_token]
18
+ message: "#{obj_type} '#{class_idx[:name_token].value}' contains illegal uppercase",
19
+ line: class_idx[:name_token].line,
20
+ column: class_idx[:name_token].column,
21
+ token: class_idx[:name_token],
22
+ description: 'Find and warn about module names with illegal uppercase characters.',
23
+ help_uri: 'https://puppet.com/docs/puppet/latest/modules_fundamentals.html#allowed-module-names',
22
24
  )
23
25
  end
24
26
  end
@@ -17,9 +17,11 @@ PuppetLint.new_check(:nested_classes_or_defines) do
17
17
 
18
18
  notify(
19
19
  :warning,
20
- :message => "#{type} defined inside a class",
21
- :line => token.line,
22
- :column => token.column
20
+ message: "#{type} defined inside a class",
21
+ line: token.line,
22
+ column: token.column,
23
+ description: 'Test the manifest tokens for any classes or defined types that are defined inside another class.',
24
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#nested-classes-or-defined-types',
23
25
  )
24
26
  end
25
27
  end
@@ -31,9 +31,12 @@ PuppetLint.new_check(:parameter_order) do
31
31
  msg = 'optional parameter listed before required parameter'
32
32
  notify(
33
33
  :warning,
34
- :message => msg,
35
- :line => token.line,
36
- :column => token.column
34
+ message: msg,
35
+ line: token.line,
36
+ column: token.column,
37
+ description: 'Test the manifest tokens for any parameterised classes or defined types that take '\
38
+ 'parameters and record a warning if there are any optional parameters listed before required parameters.',
39
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order-of-parameters',
37
40
  )
38
41
  end
39
42
  end
@@ -52,7 +55,7 @@ PuppetLint.new_check(:parameter_order) do
52
55
  end
53
56
 
54
57
  def required_parameter?(token)
55
- data_type = token.prev_token_of(:TYPE, :skip_blocks => true)
58
+ data_type = token.prev_token_of(:TYPE, skip_blocks: true)
56
59
  return false if data_type && data_type.value == 'Optional'
57
60
 
58
61
  if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
@@ -7,9 +7,11 @@ PuppetLint.new_check(:right_to_left_relationship) do
7
7
  tokens.select { |r| r.type == :OUT_EDGE }.each do |token|
8
8
  notify(
9
9
  :warning,
10
- :message => 'right-to-left (<-) relationship',
11
- :line => token.line,
12
- :column => token.column
10
+ message: 'right-to-left (<-) relationship',
11
+ line: token.line,
12
+ column: token.column,
13
+ description: 'Test the manifest tokens for any right-to-left (<-) chaining operators and record a warning for each instance found.',
14
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#chaining-arrow-syntax',
13
15
  )
14
16
  end
15
17
  end
@@ -41,13 +41,11 @@ PuppetLint.new_check(:variable_scope) do
41
41
  referenced_variables = Set[]
42
42
  object_tokens = idx[:tokens]
43
43
 
44
- unless idx[:param_tokens].nil?
45
- idx[:param_tokens].each do |token|
46
- next unless token.type == :VARIABLE
47
- next unless POST_VAR_TOKENS.include?(token.next_code_token.type)
44
+ idx[:param_tokens]&.each do |token|
45
+ next unless token.type == :VARIABLE
46
+ next unless POST_VAR_TOKENS.include?(token.next_code_token.type)
48
47
 
49
- variables_in_scope << token.value
50
- end
48
+ variables_in_scope << token.value
51
49
  end
52
50
 
53
51
  future_parser_scopes = {}
@@ -63,7 +61,7 @@ PuppetLint.new_check(:variable_scope) do
63
61
  temp_token = token
64
62
 
65
63
  brack_depth = 0
66
- while temp_token = temp_token.prev_code_token
64
+ while (temp_token = temp_token.prev_code_token)
67
65
  case temp_token.type
68
66
  when :VARIABLE
69
67
  variables_in_scope << temp_token.value
@@ -72,7 +70,7 @@ PuppetLint.new_check(:variable_scope) do
72
70
  when :LBRACK
73
71
  brack_depth -= 1
74
72
  break if brack_depth.zero?
75
- when :COMMA # rubocop:disable Lint/EmptyWhen
73
+ when :COMMA
76
74
  # ignore
77
75
  else # unexpected
78
76
  break
@@ -124,15 +122,19 @@ PuppetLint.new_check(:variable_scope) do
124
122
  end
125
123
 
126
124
  next if token.value.include?('::')
127
- next if token.value =~ %r{^(facts|trusted)\[.+\]}
125
+ next if %r{^(facts|trusted)\[.+\]}.match?(token.value)
128
126
  next if variables_in_scope.include?(token.value.gsub(%r{\[.+\]\Z}, ''))
129
- next if token.value =~ %r{\A\d+\Z}
127
+ next if %r{\A\d+\Z}.match?(token.value)
130
128
 
131
129
  notify(
132
130
  :warning,
133
- :message => msg,
134
- :line => token.line,
135
- :column => token.column
131
+ message: msg,
132
+ line: token.line,
133
+ column: token.column,
134
+ description: 'Test the manifest tokens for any variables that are referenced in the manifest. ' \
135
+ 'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \
136
+ 'check that they have been defined in the local scope and record a warning for each variable that has not.',
137
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables',
136
138
  )
137
139
  end
138
140
  end
@@ -4,15 +4,17 @@
4
4
  # https://puppet.com/docs/puppet/latest/style_guide.html#comments
5
5
  PuppetLint.new_check(:slash_comments) do
6
6
  def check
7
- tokens.select { |token|
8
- token.type == :SLASH_COMMENT
9
- }.each do |token|
7
+ invalid_tokens = tokens.select { |token| token.type == :SLASH_COMMENT }
8
+
9
+ invalid_tokens.each do |token|
10
10
  notify(
11
11
  :warning,
12
- :message => '// comment found',
13
- :line => token.line,
14
- :column => token.column,
15
- :token => token
12
+ message: '// comment found',
13
+ line: token.line,
14
+ column: token.column,
15
+ token: token,
16
+ description: 'Check the manifest tokens for any comments started with slashes (//) and record a warning for each instance found.',
17
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#comments',
16
18
  )
17
19
  end
18
20
  end
@@ -4,15 +4,17 @@
4
4
  # https://puppet.com/docs/puppet/latest/style_guide.html#comments
5
5
  PuppetLint.new_check(:star_comments) do
6
6
  def check
7
- tokens.select { |token|
8
- token.type == :MLCOMMENT
9
- }.each do |token|
7
+ invalid_tokens = tokens.select { |token| token.type == :MLCOMMENT }
8
+
9
+ invalid_tokens.each do |token|
10
10
  notify(
11
11
  :warning,
12
- :message => '/* */ comment found',
13
- :line => token.line,
14
- :column => token.column,
15
- :token => token
12
+ message: '/* */ comment found',
13
+ line: token.line,
14
+ column: token.column,
15
+ token: token,
16
+ description: 'Check the manifest tokens for any comments encapsulated with slash-asterisks (/* */) and record a warning for each instance found.',
17
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#comments',
16
18
  )
17
19
  end
18
20
  end
@@ -25,7 +27,7 @@ PuppetLint.new_check(:star_comments) do
25
27
  problem[:token].value = " #{first_line}"
26
28
 
27
29
  index = tokens.index(problem[:token].next_token) || 1
28
- comment_lines.reverse.each do |line|
30
+ comment_lines.reverse_each do |line|
29
31
  indent = problem[:token].prev_token.nil? ? nil : problem[:token].prev_token.value.dup
30
32
  add_token(index, PuppetLint::Lexer::Token.new(:COMMENT, " #{line}", 0, 0))
31
33
  add_token(index, PuppetLint::Lexer::Token.new(:INDENT, indent, 0, 0)) if indent
@@ -17,7 +17,7 @@ PuppetLint.new_check(:case_without_default) do
17
17
  elsif tokens[idx].type == :RBRACE
18
18
  depth -= 1
19
19
  if depth.zero?
20
- case_indexes << { :start => token_idx, :end => idx }
20
+ case_indexes << { start: token_idx, end: idx }
21
21
  break
22
22
  end
23
23
  end
@@ -49,9 +49,11 @@ PuppetLint.new_check(:case_without_default) do
49
49
 
50
50
  notify(
51
51
  :warning,
52
- :message => 'case statement without a default case',
53
- :line => case_tokens.first.line,
54
- :column => case_tokens.first.column
52
+ message: 'case statement without a default case',
53
+ line: case_tokens.first.line,
54
+ column: case_tokens.first.column,
55
+ description: 'Test the manifest tokens for any case statements that do not contain a "default" case and record a warning for each instance found.',
56
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#defaults-for-case-statements-and-selectors',
55
57
  )
56
58
  end
57
59
  end
@@ -12,9 +12,11 @@ PuppetLint.new_check(:selector_inside_resource) do
12
12
 
13
13
  notify(
14
14
  :warning,
15
- :message => 'selector inside resource block',
16
- :line => token.line,
17
- :column => token.column
15
+ message: 'selector inside resource block',
16
+ line: token.line,
17
+ column: token.column,
18
+ description: 'Test the manifest tokens for any selectors embedded within resource declarations and record a warning for each instance found.',
19
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#keep-resource-declarations-simple',
18
20
  )
19
21
  end
20
22
  end
@@ -22,9 +22,13 @@ PuppetLint.new_check(:documentation) do
22
22
 
23
23
  notify(
24
24
  :warning,
25
- :message => "#{type} not documented",
26
- :line => first_token.line,
27
- :column => first_token.column
25
+ message: "#{type} not documented",
26
+ line: first_token.line,
27
+ column: first_token.column,
28
+ description: 'Check the manifest tokens for any class or defined type that does not '\
29
+ 'have a comment directly above it (hopefully, explaining the usage of it) and record '\
30
+ 'a warning for each instance found.',
31
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private',
28
32
  )
29
33
  end
30
34
  end
@@ -11,25 +11,29 @@ PuppetLint.new_check(:unquoted_node_name) do
11
11
  if node_lbrace_tok.nil?
12
12
  notify(
13
13
  :error,
14
- :check => :syntax,
15
- :message => 'Syntax error (try running `puppet parser validate <file>`)',
16
- :line => node.line,
17
- :column => node.column
14
+ check: :syntax,
15
+ message: 'Syntax error (try running `puppet parser validate <file>`)',
16
+ line: node.line,
17
+ column: node.column,
18
+ description: 'Check for any syntax error and record an error of each instance found.',
19
+ help_uri: nil,
18
20
  )
19
21
  next
20
22
  end
21
23
 
22
24
  node_lbrace_idx = tokens.index(node_lbrace_tok)
23
25
 
24
- tokens[node_token_idx..node_lbrace_idx].select { |token|
25
- token.type == :NAME && token.value != 'default'
26
- }.each do |token|
26
+ invalid_tokens = tokens[node_token_idx..node_lbrace_idx].select { |token| token.type == :NAME && token.value != 'default' }
27
+
28
+ invalid_tokens.each do |token|
27
29
  notify(
28
30
  :warning,
29
- :message => 'unquoted node name found',
30
- :line => token.line,
31
- :column => token.column,
32
- :token => token
31
+ message: 'unquoted node name found',
32
+ line: token.line,
33
+ column: token.column,
34
+ token: token,
35
+ description: 'Check the manifest for unquoted node names and record a warning for each instance found.',
36
+ help_uri: nil,
33
37
  )
34
38
  end
35
39
  end
@@ -24,9 +24,11 @@ PuppetLint.new_check(:duplicate_params) do
24
24
  if (seen_params[level] ||= Set.new).include?(prev_token.value)
25
25
  notify(
26
26
  :error,
27
- :message => 'duplicate parameter found in resource',
28
- :line => prev_token.line,
29
- :column => prev_token.column
27
+ message: 'duplicate parameter found in resource',
28
+ line: prev_token.line,
29
+ column: prev_token.column,
30
+ description: 'Check the tokens of each resource instance for any duplicate parameters and record a warning for each instance found.',
31
+ help_uri: nil,
30
32
  )
31
33
  else
32
34
  seen_params[level] << prev_token.value
@@ -17,10 +17,13 @@ PuppetLint.new_check(:ensure_first_param) do
17
17
  ensure_token = resource[:param_tokens][ensure_attr_index]
18
18
  notify(
19
19
  :warning,
20
- :message => "ensure found on line but it's not the first attribute",
21
- :line => ensure_token.line,
22
- :column => ensure_token.column,
23
- :resource => resource
20
+ message: "ensure found on line but it's not the first attribute",
21
+ line: ensure_token.line,
22
+ column: ensure_token.column,
23
+ resource: resource,
24
+ description: 'Check the tokens of each resource instance for an ensure parameter and if '\
25
+ 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.',
26
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering',
24
27
  )
25
28
  end
26
29
  end
@@ -28,7 +31,7 @@ PuppetLint.new_check(:ensure_first_param) do
28
31
  def fix(problem)
29
32
  first_param_name_token = problem[:resource][:param_tokens].first
30
33
  first_param_comma_token = first_param_name_token.next_token_of(:COMMA)
31
- ensure_param_name_token = first_param_comma_token.next_token_of(:NAME, :value => 'ensure')
34
+ ensure_param_name_token = first_param_comma_token.next_token_of(:NAME, value: 'ensure')
32
35
 
33
36
  raise PuppetLint::NoFix if ensure_param_name_token.nil?
34
37
 
@@ -8,19 +8,22 @@ PuppetLint.new_check(:ensure_not_symlink_target) do
8
8
  resource_indexes.each do |resource|
9
9
  next unless resource[:type].value == 'file'
10
10
 
11
- resource[:param_tokens].select { |param_token|
12
- param_token.value == 'ensure'
13
- }.each do |ensure_token|
11
+ resources = resource[:param_tokens].select { |param_token| param_token.value == 'ensure' }
12
+
13
+ resources.each do |ensure_token|
14
14
  value_token = ensure_token.next_code_token.next_code_token
15
15
  next unless value_token.value.start_with?('/')
16
16
 
17
17
  notify(
18
18
  :warning,
19
- :message => 'symlink target specified in ensure attr',
20
- :line => value_token.line,
21
- :column => value_token.column,
22
- :param_token => ensure_token,
23
- :value_token => value_token
19
+ message: 'symlink target specified in ensure attr',
20
+ line: value_token.line,
21
+ column: value_token.column,
22
+ param_token: ensure_token,
23
+ value_token: value_token,
24
+ description: 'Check the tokens of each File resource instance for an ensure parameter and '\
25
+ 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').',
26
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links',
24
27
  )
25
28
  end
26
29
  end
@@ -7,33 +7,38 @@ PuppetLint.new_check(:file_mode) do
7
7
  MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze
8
8
  SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze
9
9
  IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME]
10
- MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}
10
+ MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze
11
11
 
12
12
  def check
13
13
  resource_indexes.each do |resource|
14
14
  next unless resource[:type].value == 'file' || resource[:type].value == 'concat'
15
15
 
16
- resource[:param_tokens].select { |param_token|
16
+ resources = resource[:param_tokens].select do |param_token|
17
17
  param_token.value == 'mode'
18
- }.each do |param_token|
18
+ end
19
+
20
+ resources.each do |param_token|
19
21
  value_token = param_token.next_code_token.next_code_token
20
22
 
21
23
  break if IGNORE_TYPES.include?(value_token.type)
22
- break if value_token.value =~ MODE_RE
24
+ break if MODE_RE.match?(value_token.value)
23
25
 
24
26
  notify(
25
27
  :warning,
26
- :message => MSG,
27
- :line => value_token.line,
28
- :column => value_token.column,
29
- :token => value_token
28
+ message: MSG,
29
+ line: value_token.line,
30
+ column: value_token.column,
31
+ token: value_token,
32
+ description: 'Check the tokens of each File resource instance for a mode parameter and if found, ' \
33
+ 'record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (\'o=rwx,g\+r\').',
34
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes',
30
35
  )
31
36
  end
32
37
  end
33
38
  end
34
39
 
35
40
  def fix(problem)
36
- raise PuppetLint::NoFix unless problem[:token].value =~ %r{\A[0-7]{3}\Z}
41
+ raise PuppetLint::NoFix unless %r{\A[0-7]{3}\Z}.match?(problem[:token].value)
37
42
 
38
43
  problem[:token].type = :SSTRING
39
44
  problem[:token].value = "0#{problem[:token].value}"
@@ -10,17 +10,22 @@ PuppetLint.new_check(:unquoted_file_mode) do
10
10
  resource_indexes.each do |resource|
11
11
  next unless resource[:type].value == 'file' || resource[:type].value == 'concat'
12
12
 
13
- resource[:param_tokens].select { |param_token|
13
+ resources = resource[:param_tokens].select do |param_token|
14
14
  param_token.value == 'mode' &&
15
15
  TOKEN_TYPES.include?(param_token.next_code_token.next_code_token.type)
16
- }.each do |param_token|
16
+ end
17
+
18
+ resources.each do |param_token|
17
19
  value_token = param_token.next_code_token.next_code_token
18
20
  notify(
19
21
  :warning,
20
- :message => 'unquoted file mode',
21
- :line => value_token.line,
22
- :column => value_token.column,
23
- :token => value_token
22
+ message: 'unquoted file mode',
23
+ line: value_token.line,
24
+ column: value_token.column,
25
+ token: value_token,
26
+ description: 'Check the tokens of each File resource instance for a mode parameter '\
27
+ 'and if found, record a warning if the value of that parameter is not a quoted string.',
28
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes',
24
29
  )
25
30
  end
26
31
  end
@@ -9,10 +9,12 @@ PuppetLint.new_check(:unquoted_resource_title) do
9
9
 
10
10
  notify(
11
11
  :warning,
12
- :message => 'unquoted resource title',
13
- :line => token.line,
14
- :column => token.column,
15
- :token => token
12
+ message: 'unquoted resource title',
13
+ line: token.line,
14
+ column: token.column,
15
+ token: token,
16
+ description: 'Check the manifest tokens for any resource titles / namevars that are not quoted and record a warning for each instance found.',
17
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#resource-names',
16
18
  )
17
19
  end
18
20
  end