puppet-lint 2.5.2 → 3.0.0

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 +63 -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
@@ -4,19 +4,24 @@
4
4
  #
5
5
  # https://puppet.com/docs/puppet/latest/style_guide.html#quoting
6
6
  PuppetLint.new_check(:double_quoted_strings) do
7
- ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}
7
+ ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze
8
8
 
9
9
  def check
10
- tokens.select { |token|
10
+ invalid_tokens = tokens.select do |token|
11
11
  token.type == :STRING &&
12
12
  token.value.gsub(' ' * token.column, "\n")[ESCAPE_CHAR_RE].nil?
13
- }.each do |token|
13
+ end
14
+
15
+ invalid_tokens.each do |token|
14
16
  notify(
15
17
  :warning,
16
- :message => 'double quoted string containing no variables',
17
- :line => token.line,
18
- :column => token.column,
19
- :token => token
18
+ message: 'double quoted string containing no variables',
19
+ line: token.line,
20
+ column: token.column,
21
+ token: token,
22
+ description: 'Check the manifest tokens for any double quoted strings that don\'t '\
23
+ 'contain any variables or common escape characters and record a warning for each instance found.',
24
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
20
25
  )
21
26
  end
22
27
  end
@@ -25,12 +25,14 @@ PuppetLint.new_check(:only_variable_string) do
25
25
  end
26
26
  notify(
27
27
  :warning,
28
- :message => 'string containing only a variable',
29
- :line => var_token.line,
30
- :column => var_token.column,
31
- :start_token => start_token,
32
- :var_token => var_token,
33
- :end_token => eos_token
28
+ message: 'string containing only a variable',
29
+ line: var_token.line,
30
+ column: var_token.column,
31
+ start_token: start_token,
32
+ var_token: var_token,
33
+ end_token: eos_token,
34
+ description: 'Check the manifest tokens for double quoted strings that contain a single variable only and record a warning for each instance found.',
35
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
34
36
  )
35
37
  end
36
38
  break
@@ -5,17 +5,23 @@
5
5
  # No style guide reference
6
6
  PuppetLint.new_check(:puppet_url_without_modules) do
7
7
  def check
8
- tokens.select { |token|
8
+ puppet_urls = tokens.select do |token|
9
9
  (token.type == :SSTRING || token.type == :STRING || token.type == :DQPRE) && token.value.start_with?('puppet://')
10
- }.reject { |token|
11
- token.value[%r{puppet://.*?/(.+)}, 1].start_with?('modules/') unless token.value[%r{puppet://.*?/(.+)}, 1].nil?
12
- }.each do |token|
10
+ end
11
+
12
+ invalid_urls = puppet_urls.reject do |token|
13
+ token.value[%r{puppet://.*?/(.+)}, 1]&.start_with?('modules/')
14
+ end
15
+
16
+ invalid_urls.each do |token|
13
17
  notify(
14
18
  :warning,
15
- :message => 'puppet:// URL without modules/ found',
16
- :line => token.line,
17
- :column => token.column,
18
- :token => token
19
+ message: 'puppet:// URL without modules/ found',
20
+ line: token.line,
21
+ column: token.column,
22
+ token: token,
23
+ description: 'Check the manifest tokens for any puppet:// URL strings where the path section doesn\'t start with modules/ and record a warning for each instance found.',
24
+ help_uri: nil,
19
25
  )
20
26
  end
21
27
  end
@@ -8,15 +8,19 @@ PuppetLint.new_check(:quoted_booleans) do
8
8
  BOOLEANS = Set['true', 'false']
9
9
 
10
10
  def check
11
- tokens.select { |r|
12
- STRING_TYPES.include?(r.type) && BOOLEANS.include?(r.value)
13
- }.each do |token|
11
+ invalid_tokens = tokens.select do |token|
12
+ STRING_TYPES.include?(token.type) && BOOLEANS.include?(token.value)
13
+ end
14
+
15
+ invalid_tokens.each do |token|
14
16
  notify(
15
17
  :warning,
16
- :message => 'quoted boolean value found',
17
- :line => token.line,
18
- :column => token.column,
19
- :token => token
18
+ message: 'quoted boolean value found',
19
+ line: token.line,
20
+ column: token.column,
21
+ token: token,
22
+ description: 'Check the manifest tokens for any double or single quoted strings containing only a boolean value and record a warning for each instance found.',
23
+ help_uri: nil,
20
24
  )
21
25
  end
22
26
  end
@@ -4,14 +4,19 @@
4
4
  # https://puppet.com/docs/puppet/latest/style_guide.html#quoting
5
5
  PuppetLint.new_check(:single_quote_string_with_variables) do
6
6
  def check
7
- tokens.select { |r|
8
- r.type == :SSTRING && r.value.include?('${') && !r.prev_token.prev_token.value.match(%r{inline_(epp|template)})
9
- }.each do |token|
7
+ invalid_tokens = tokens.select do |token|
8
+ token.type == :SSTRING && token.value.include?('${') && !token.prev_token.prev_token.value.match(%r{inline_(epp|template)})
9
+ end
10
+
11
+ invalid_tokens.each do |token|
10
12
  notify(
11
13
  :error,
12
- :message => 'single quoted string containing a variable found',
13
- :line => token.line,
14
- :column => token.column
14
+ message: 'single quoted string containing a variable found',
15
+ line: token.line,
16
+ column: token.column,
17
+ description: 'Check the manifest tokens for any single quoted strings containing '\
18
+ 'a enclosed variable and record an error for each instance found.',
19
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
15
20
  )
16
21
  end
17
22
  end
@@ -15,15 +15,19 @@ PuppetLint.new_check(:variables_not_enclosed) do
15
15
  ]
16
16
 
17
17
  def check
18
- tokens.select { |r|
19
- r.type == :UNENC_VARIABLE
20
- }.each do |token|
18
+ invalid_tokens = tokens.select do |token|
19
+ token.type == :UNENC_VARIABLE
20
+ end
21
+
22
+ invalid_tokens.each do |token|
21
23
  notify(
22
24
  :warning,
23
- :message => 'variable not enclosed in {}',
24
- :line => token.line,
25
- :column => token.column,
26
- :token => token
25
+ message: 'variable not enclosed in {}',
26
+ line: token.line,
27
+ column: token.column,
28
+ token: token,
29
+ description: 'Check the manifest tokens for any variables in a string that have not been enclosed by braces ({}) and record a warning for each instance found.',
30
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
27
31
  )
28
32
  end
29
33
  end
@@ -38,7 +42,7 @@ PuppetLint.new_check(:variables_not_enclosed) do
38
42
  scanner = StringScanner.new(token.value)
39
43
 
40
44
  brack_depth = 0
41
- result = { :ref => '' }
45
+ result = { ref: '' }
42
46
 
43
47
  until scanner.eos?
44
48
  result[:ref] += scanner.getch
@@ -6,16 +6,20 @@ PuppetLint.new_check(:variable_contains_dash) do
6
6
  VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
7
7
 
8
8
  def check
9
- tokens.select { |r|
10
- VARIABLE_DASH_TYPES.include?(r.type)
11
- }.each do |token|
12
- next unless token.value.gsub(%r{\[.+?\]}, '') =~ %r{-}
9
+ invalid_tokens = tokens.select do |token|
10
+ VARIABLE_DASH_TYPES.include?(token.type)
11
+ end
12
+
13
+ invalid_tokens.each do |token|
14
+ next unless %r{-}.match?(token.value.gsub(%r{\[.+?\]}, ''))
13
15
 
14
16
  notify(
15
17
  :warning,
16
- :message => 'variable contains a dash',
17
- :line => token.line,
18
- :column => token.column
18
+ message: 'variable contains a dash',
19
+ line: token.line,
20
+ column: token.column,
21
+ description: 'Test the manifest tokens for variables that contain a dash and record a warning for each instance found.',
22
+ help_uri: nil,
19
23
  )
20
24
  end
21
25
  end
@@ -6,16 +6,20 @@ PuppetLint.new_check(:variable_is_lowercase) do
6
6
  VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
7
7
 
8
8
  def check
9
- tokens.select { |r|
10
- VARIABLE_LOWERCASE_TYPES.include?(r.type)
11
- }.each do |token|
12
- next unless token.value.gsub(%r{\[.+?\]}, '') =~ %r{[A-Z]}
9
+ invalid_tokens = tokens.select do |token|
10
+ VARIABLE_LOWERCASE_TYPES.include?(token.type)
11
+ end
12
+
13
+ invalid_tokens.each do |token|
14
+ next unless %r{[A-Z]}.match?(token.value.gsub(%r{\[.+?\]}, ''))
13
15
 
14
16
  notify(
15
17
  :warning,
16
- :message => 'variable contains an uppercase letter',
17
- :line => token.line,
18
- :column => token.column
18
+ message: 'variable contains an uppercase letter',
19
+ line: token.line,
20
+ column: token.column,
21
+ description: 'Test the manifest tokens for variables that contain an uppercase letter and record a warning for each instance found.',
22
+ help_uri: nil,
19
23
  )
20
24
  end
21
25
  end
@@ -7,15 +7,10 @@
7
7
  PuppetLint.new_check(:'140chars') do
8
8
  def check
9
9
  manifest_lines.each_with_index do |line, idx|
10
- next if line =~ %r{://} || line =~ %r{template\(}
11
- next unless line.scan(%r{.}mu).size > 140
10
+ result = PuppetLint::LineLengthCheck.check(idx + 1, line, 140)
12
11
 
13
- notify(
14
- :warning,
15
- :message => 'line has more than 140 characters',
16
- :line => idx + 1,
17
- :column => 140
18
- )
12
+ next if result.nil?
13
+ notify(*result)
19
14
  end
20
15
  end
21
16
  end
@@ -4,16 +4,18 @@
4
4
  # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace
5
5
  PuppetLint.new_check(:'2sp_soft_tabs') do
6
6
  def check
7
- tokens.select { |r|
8
- r.type == :INDENT
9
- }.reject { |r|
10
- r.value.length.even?
11
- }.each do |token|
7
+ indents = tokens.select { |token| token.type == :INDENT }
8
+
9
+ invalid_indents = indents.reject { |token| token.value.length.even? }
10
+
11
+ invalid_indents.each do |token|
12
12
  notify(
13
13
  :error,
14
- :message => 'two-space soft tabs not used',
15
- :line => token.line,
16
- :column => token.column
14
+ message: 'two-space soft tabs not used',
15
+ line: token.line,
16
+ column: token.column,
17
+ description: 'Check the manifest tokens for any indentation not using 2 space soft tabs and record an error for each instance found.',
18
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
17
19
  )
18
20
  end
19
21
  end
@@ -6,15 +6,10 @@
6
6
  PuppetLint.new_check(:'80chars') do
7
7
  def check
8
8
  manifest_lines.each_with_index do |line, idx|
9
- next if line =~ %r{://} || line =~ %r{template\(}
10
- next unless line.scan(%r{.}mu).size > 80
9
+ result = PuppetLint::LineLengthCheck.check(idx + 1, line, 80)
11
10
 
12
- notify(
13
- :warning,
14
- :message => 'line has more than 80 characters',
15
- :line => idx + 1,
16
- :column => 80
17
- )
11
+ next if result.nil?
12
+ notify(*result)
18
13
  end
19
14
  end
20
15
  end
@@ -72,13 +72,15 @@ PuppetLint.new_check(:arrow_alignment) do
72
72
  arrows_on_line = level_tokens[level_idx].select { |t| t.line == arrow_tok.line }
73
73
  notify(
74
74
  :warning,
75
- :message => "indentation of => is not properly aligned (expected in column #{arrow_column[level_idx]}, but found it in column #{arrow_tok.column})",
76
- :line => arrow_tok.line,
77
- :column => arrow_tok.column,
78
- :token => arrow_tok,
79
- :arrow_column => arrow_column[level_idx],
80
- :newline => arrows_on_line.index(arrow_tok) != 0,
81
- :newline_indent => param_column[level_idx] - 1
75
+ message: "indentation of => is not properly aligned (expected in column #{arrow_column[level_idx]}, but found it in column #{arrow_tok.column})",
76
+ line: arrow_tok.line,
77
+ column: arrow_tok.column,
78
+ token: arrow_tok,
79
+ arrow_column: arrow_column[level_idx],
80
+ newline: arrows_on_line.index(arrow_tok) != 0,
81
+ newline_indent: param_column[level_idx] - 1,
82
+ description: 'Check the manifest tokens for any arrows (=>) in a grouping ({}) that are not aligned with other arrows in that grouping.',
83
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
82
84
  )
83
85
  end
84
86
  end
@@ -104,7 +106,7 @@ PuppetLint.new_check(:arrow_alignment) do
104
106
 
105
107
  end_param_idx = tokens.index(problem[:token].prev_code_token)
106
108
  start_param_idx = tokens.index(problem[:token].prev_token_of([:INDENT, :NEWLINE]))
107
- param_length = tokens[start_param_idx..end_param_idx].map { |r| r.to_manifest.length }.reduce(0) { |sum, x| sum + x } + 1
109
+ param_length = tokens[start_param_idx..end_param_idx].sum { |r| r.to_manifest.length } + 1
108
110
  new_ws_len = problem[:arrow_column] - param_length
109
111
  else
110
112
  new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
@@ -6,15 +6,19 @@ PuppetLint.new_check(:hard_tabs) do
6
6
  WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
7
7
 
8
8
  def check
9
- tokens.select { |r|
10
- WHITESPACE_TYPES.include?(r.type) && r.value.include?("\t")
11
- }.each do |token|
9
+ invalid_tokens = tokens.select do |token|
10
+ WHITESPACE_TYPES.include?(token.type) && token.value.include?("\t")
11
+ end
12
+
13
+ invalid_tokens.each do |token|
12
14
  notify(
13
15
  :error,
14
- :message => 'tab character found',
15
- :line => token.line,
16
- :column => token.column,
17
- :token => token
16
+ message: 'tab character found',
17
+ line: token.line,
18
+ column: token.column,
19
+ token: token,
20
+ description: 'Check the raw manifest string for lines containing hard tab characters and record an error for each instance found.',
21
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
18
22
  )
19
23
  end
20
24
  end
@@ -0,0 +1,29 @@
1
+ # A utility class for checking the length of a given string.
2
+ class PuppetLint::LineLengthCheck
3
+ # Check the current line to determine if it is more than character_count
4
+ # and record a warning if an instance is found. The only exceptions
5
+ # to this rule are lines containing URLs and template() calls which would hurt
6
+ # readability if split.
7
+ #
8
+ # @param line_number [Integer] The line number of the current line.
9
+ # @param content [String] The content of the current line.
10
+ # @param character_count [Integer] The maximum number of characters allowed
11
+ #
12
+ # @return problem [Array] An array containing a description of the problem.
13
+ # Can be passed directly to notify..
14
+ def self.check(line_number, content, character_count)
15
+ return if content.include? '://'
16
+ return if content.include? 'template('
17
+ return unless content.scan(%r{.}mu).size > character_count
18
+
19
+ [
20
+ :warning,
21
+ message: "line has more than #{character_count} characters",
22
+ line: line_number,
23
+ column: character_count,
24
+ description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. '\
25
+ 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.',
26
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
27
+ ]
28
+ end
29
+ end
@@ -4,17 +4,23 @@
4
4
  # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace
5
5
  PuppetLint.new_check(:trailing_whitespace) do
6
6
  def check
7
- tokens.select { |token|
7
+ whitespace = tokens.select do |token|
8
8
  [:WHITESPACE, :INDENT].include?(token.type)
9
- }.select { |token|
9
+ end
10
+
11
+ whitespace_at_eol = whitespace.select do |token|
10
12
  token.next_token.nil? || token.next_token.type == :NEWLINE
11
- }.each do |token|
13
+ end
14
+
15
+ whitespace_at_eol.each do |token|
12
16
  notify(
13
17
  :error,
14
- :message => 'trailing whitespace found',
15
- :line => token.line,
16
- :column => token.column,
17
- :token => token
18
+ message: 'trailing whitespace found',
19
+ line: token.line,
20
+ column: token.column,
21
+ token: token,
22
+ description: 'Check the manifest tokens for lines ending with whitespace and record an error for each instance found.',
23
+ help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace',
18
24
  )
19
25
  end
20
26
  end
@@ -1,77 +1,79 @@
1
1
  require 'pathname'
2
2
 
3
- class PuppetLint
4
- # Public: Various methods that implement puppet-lint's plugin system
3
+ # Public: Various methods that implement puppet-lint's plugin system
4
+ #
5
+ # Examples
6
+ #
7
+ # PuppetLint::Plugins.load_spec_helper
8
+ class PuppetLint::Plugins
9
+ # Internal: Find any gems containing puppet-lint plugins and load them.
5
10
  #
6
- # Examples
7
- #
8
- # PuppetLint::Plugins.load_spec_helper
9
- class Plugins
10
- # Internal: Find any gems containing puppet-lint plugins and load them.
11
- #
12
- # Returns nothing.
13
- def self.load_from_gems
14
- gem_directories.select { |path|
15
- (path + 'puppet-lint/plugins').directory?
16
- }.each do |gem_path|
17
- Dir["#{gem_path + 'puppet-lint/plugins'}/*.rb"].each do |file|
18
- load(file)
19
- end
20
- end
11
+ # Returns nothing.
12
+ def self.load_from_gems
13
+ plugins_directories = gem_directories.select do |directory|
14
+ (directory + 'puppet-lint/plugins').to_s if (directory + 'puppet-lint/plugins').directory?
21
15
  end
22
16
 
23
- # Public: Load the puppet-lint spec_helper.rb
24
- #
25
- # Returns nothings.
26
- def self.load_spec_helper
27
- gemspec = gemspecs.select { |spec| spec.name == 'puppet-lint' }.first
28
- load(Pathname.new(gemspec.full_gem_path) + 'spec/spec_helper.rb')
17
+ plugin_files = plugins_directories.each do |directory|
18
+ Dir["#{directory}/**/*.rb"]
29
19
  end
30
20
 
31
- class << self
32
- private
21
+ plugin_files.each do |file|
22
+ load(file)
23
+ end
24
+ end
33
25
 
34
- # Internal: Check if RubyGems is loaded and available.
35
- #
36
- # Returns true if RubyGems is available, false if not.
37
- def rubygems?
38
- defined?(::Gem)
39
- end
26
+ # Public: Load the puppet-lint spec_helper.rb
27
+ #
28
+ # Returns nothings.
29
+ def self.load_spec_helper
30
+ gemspec = gemspecs.find { |spec| spec.name == 'puppet-lint' }
31
+ load(Pathname.new(gemspec.full_gem_path) + 'spec/spec_helper.rb')
32
+ end
40
33
 
41
- # Internal: Retrieve a list of avaliable gemspecs.
42
- #
43
- # Returns an Array of Gem::Specification objects.
44
- def gemspecs
45
- @gemspecs ||= if Gem::Specification.respond_to?(:latest_specs)
46
- Gem::Specification.latest_specs(load_prerelease_plugins?)
47
- else
48
- Gem.searcher.init_gemspecs
49
- end
50
- end
34
+ class << self
35
+ private
51
36
 
52
- # Internal: Determine whether to load plugins that contain a letter in their version number.
53
- #
54
- # Returns true if the configuration is set to load "prerelease" gems, false otherwise.
55
- def load_prerelease_plugins?
56
- # Load prerelease plugins (which ruby defines as any gem which has a letter in its version number).
57
- # Can't use puppet-lint configuration object here because this code executes before the command line is parsed.
58
- if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS']
59
- return %w[true yes].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase)
60
- end
61
- false
37
+ # Internal: Check if RubyGems is loaded and available.
38
+ #
39
+ # Returns true if RubyGems is available, false if not.
40
+ def rubygems?
41
+ defined?(::Gem)
42
+ end
43
+
44
+ # Internal: Retrieve a list of avaliable gemspecs.
45
+ #
46
+ # Returns an Array of Gem::Specification objects.
47
+ def gemspecs
48
+ @gemspecs ||= if Gem::Specification.respond_to?(:latest_specs)
49
+ Gem::Specification.latest_specs(load_prerelease_plugins?)
50
+ else
51
+ Gem.searcher.init_gemspecs
52
+ end
53
+ end
54
+
55
+ # Internal: Determine whether to load plugins that contain a letter in their version number.
56
+ #
57
+ # Returns true if the configuration is set to load "prerelease" gems, false otherwise.
58
+ def load_prerelease_plugins?
59
+ # Load prerelease plugins (which ruby defines as any gem which has a letter in its version number).
60
+ # Can't use puppet-lint configuration object here because this code executes before the command line is parsed.
61
+ if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS']
62
+ return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase)
62
63
  end
64
+ false
65
+ end
63
66
 
64
- # Internal: Retrieve a list of available gem paths from RubyGems.
65
- #
66
- # Returns an Array of Pathname objects.
67
- def gem_directories
68
- if rubygems?
69
- gemspecs.reject { |spec| spec.name == 'puppet-lint' }.map do |spec|
70
- Pathname.new(spec.full_gem_path) + 'lib'
71
- end
72
- else
73
- []
67
+ # Internal: Retrieve a list of available gem paths from RubyGems.
68
+ #
69
+ # Returns an Array of Pathname objects.
70
+ def gem_directories
71
+ if rubygems?
72
+ gemspecs.reject { |spec| spec.name == 'puppet-lint' }.map do |spec|
73
+ Pathname.new(spec.full_gem_path) + 'lib'
74
74
  end
75
+ else
76
+ []
75
77
  end
76
78
  end
77
79
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PuppetLint::Report
4
+ # This formatter formats report data as GitHub Workflow commands resulting
5
+ # in GitHub check annotations when run within GitHub Actions.
6
+ class GitHubActionsReporter
7
+ ESCAPE_MAP = { '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze
8
+
9
+ def self.format_problem(file, problem)
10
+ "\n::#{problem[:kind]} file=#{file},line=#{problem[:line]},col=#{problem[:column]}::#{github_escape(problem[:message])} (check: #{problem[:check]})\n"
11
+ end
12
+
13
+ def self.github_escape(string)
14
+ string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema":"https://www.schemastore.org/schemas/json/sarif-2.1.0-rtm.5.json",
3
+ "version":"2.1.0",
4
+ "runs":[
5
+ {
6
+ "tool":{
7
+ "driver":{
8
+ "name":"Puppet Lint",
9
+ "informationUri":"https://github.com/puppetlabs/puppet-lint",
10
+ "version":"0.15.0",
11
+ "rules":[
12
+ {
13
+ "id":"",
14
+ "name":"",
15
+ "shortDescription":{
16
+ "text":""
17
+ },
18
+ "fullDescription":{
19
+ "text":""
20
+ },
21
+ "defaultConfiguration":{
22
+ "level":"warning"
23
+ },
24
+ "help":{
25
+ "text":""
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ "results":[
32
+ {
33
+ "ruleId":"",
34
+ "ruleIndex":0,
35
+ "level":"error",
36
+ "message":{
37
+ "text":""
38
+ },
39
+ "locations":[
40
+ {
41
+ "physicalLocation":{
42
+ "artifactLocation":{
43
+ "uri":"puppet-lint/spec/fixtures/test/manifests/fail.pp",
44
+ "uriBaseId":"ROOTPATH"
45
+ },
46
+ "region":{
47
+ "startLine":1,
48
+ "startColumn":1
49
+ }
50
+ }
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "columnKind":"utf16CodeUnits",
56
+ "originalUriBaseIds":{
57
+ "ROOTPATH":{
58
+ "uri":"file:///home/user/repos/"
59
+ }
60
+ }
61
+ }
62
+ ]
63
+ }