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.
- checksums.yaml +4 -4
- data/.rubocop.yml +522 -0
- data/lib/puppet-lint/bin.rb +71 -6
- data/lib/puppet-lint/checkplugin.rb +43 -9
- data/lib/puppet-lint/checks.rb +16 -16
- data/lib/puppet-lint/configuration.rb +134 -134
- data/lib/puppet-lint/data.rb +28 -28
- data/lib/puppet-lint/lexer/string_slurper.rb +138 -140
- data/lib/puppet-lint/lexer/token.rb +188 -190
- data/lib/puppet-lint/lexer.rb +416 -417
- data/lib/puppet-lint/monkeypatches.rb +1 -1
- data/lib/puppet-lint/optparser.rb +5 -1
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +6 -4
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +6 -4
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +7 -5
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +7 -4
- data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +15 -13
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +9 -7
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +10 -8
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +6 -4
- data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +5 -3
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -3
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +15 -11
- data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +5 -3
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +8 -5
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +11 -8
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +14 -9
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +11 -6
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +6 -4
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +12 -7
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +8 -6
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +14 -8
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +11 -7
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +11 -6
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +12 -8
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +11 -7
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +11 -7
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +3 -8
- data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +10 -8
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +3 -8
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +10 -8
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +11 -7
- data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +29 -0
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +13 -7
- data/lib/puppet-lint/plugins.rb +60 -61
- data/lib/puppet-lint/report/github.rb +17 -0
- data/lib/puppet-lint/report/sarif_template.json +63 -0
- data/lib/puppet-lint/tasks/puppet-lint.rb +84 -83
- data/lib/puppet-lint/tasks/release_test.rb +4 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/lib/puppet-lint.rb +27 -12
- data/spec/acceptance/puppet_lint_spec.rb +46 -0
- data/spec/spec_helper.rb +92 -91
- data/spec/spec_helper_acceptance.rb +6 -0
- data/spec/spec_helper_acceptance_local.rb +38 -0
- data/spec/{puppet-lint → unit/puppet-lint}/bin_spec.rb +79 -35
- data/spec/{puppet-lint → unit/puppet-lint}/checks_spec.rb +36 -36
- data/spec/unit/puppet-lint/configuration_spec.rb +88 -0
- data/spec/{puppet-lint → unit/puppet-lint}/data_spec.rb +6 -3
- data/spec/{puppet-lint → unit/puppet-lint}/ignore_overrides_spec.rb +17 -17
- data/spec/{puppet-lint → unit/puppet-lint}/lexer/string_slurper_spec.rb +128 -128
- data/spec/{puppet-lint → unit/puppet-lint}/lexer/token_spec.rb +1 -1
- data/spec/{puppet-lint → unit/puppet-lint}/lexer_spec.rb +653 -671
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/arrow_on_right_operand_line_spec.rb +16 -16
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/autoloader_layout_spec.rb +13 -13
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/class_inherits_from_params_class_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/code_on_top_scope_spec.rb +4 -4
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/inherits_across_namespaces_spec.rb +4 -4
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/name_contains_uppercase_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/names_containing_dash_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/nested_classes_or_defines_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/parameter_order_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/right_to_left_relationship_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/variable_scope_spec.rb +25 -25
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/slash_comments_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/star_comments_spec.rb +13 -13
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/case_without_default_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/selector_inside_resource_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_documentation/documentation_spec.rb +8 -8
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_nodes/unquoted_node_name_spec.rb +24 -24
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/duplicate_params_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_first_param_spec.rb +19 -19
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_not_symlink_target_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/file_mode_spec.rb +40 -40
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_file_mode_spec.rb +20 -20
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_resource_title_spec.rb +24 -24
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/double_quoted_strings_spec.rb +27 -27
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/only_variable_string_spec.rb +18 -18
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/puppet_url_without_modules_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/quoted_booleans_spec.rb +22 -22
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/single_quote_string_with_variables_spec.rb +2 -2
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/variables_not_enclosed_spec.rb +21 -21
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_contains_dash_spec.rb +6 -6
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_is_lowercase_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/140chars_spec.rb +5 -5
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/2sp_soft_tabs_spec.rb +2 -2
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/80chars_spec.rb +6 -6
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/arrow_alignment_spec.rb +127 -127
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/hard_tabs_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/trailing_whitespace_spec.rb +15 -15
- data/spec/unit/puppet-lint/puppet-lint_spec.rb +18 -0
- metadata +63 -119
- data/CHANGELOG.md +0 -33
- data/HISTORY.md +0 -1130
- data/spec/puppet-lint/configuration_spec.rb +0 -66
- 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
|
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
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
invalid_tokens.each do |token|
|
14
16
|
notify(
|
15
17
|
:warning,
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
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
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
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
|
8
|
+
puppet_urls = tokens.select do |token|
|
9
9
|
(token.type == :SSTRING || token.type == :STRING || token.type == :DQPRE) && token.value.start_with?('puppet://')
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
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
|
12
|
-
STRING_TYPES.include?(
|
13
|
-
|
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
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
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
|
8
|
-
|
9
|
-
|
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
|
-
:
|
13
|
-
:
|
14
|
-
:
|
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
|
19
|
-
|
20
|
-
|
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
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
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 = { :
|
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
|
10
|
-
VARIABLE_DASH_TYPES.include?(
|
11
|
-
|
12
|
-
|
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
|
-
:
|
17
|
-
:
|
18
|
-
:
|
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
|
10
|
-
VARIABLE_LOWERCASE_TYPES.include?(
|
11
|
-
|
12
|
-
|
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
|
-
:
|
17
|
-
:
|
18
|
-
:
|
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
|
-
|
11
|
-
next unless line.scan(%r{.}mu).size > 140
|
10
|
+
result = PuppetLint::LineLengthCheck.check(idx + 1, line, 140)
|
12
11
|
|
13
|
-
|
14
|
-
|
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 { |
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
:
|
15
|
-
:
|
16
|
-
:
|
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
|
-
|
10
|
-
next unless line.scan(%r{.}mu).size > 80
|
9
|
+
result = PuppetLint::LineLengthCheck.check(idx + 1, line, 80)
|
11
10
|
|
12
|
-
|
13
|
-
|
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
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
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].
|
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
|
10
|
-
WHITESPACE_TYPES.include?(
|
11
|
-
|
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
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
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
|
7
|
+
whitespace = tokens.select do |token|
|
8
8
|
[:WHITESPACE, :INDENT].include?(token.type)
|
9
|
-
|
9
|
+
end
|
10
|
+
|
11
|
+
whitespace_at_eol = whitespace.select do |token|
|
10
12
|
token.next_token.nil? || token.next_token.type == :NEWLINE
|
11
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
whitespace_at_eol.each do |token|
|
12
16
|
notify(
|
13
17
|
:error,
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
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
|
data/lib/puppet-lint/plugins.rb
CHANGED
@@ -1,77 +1,76 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
11
|
+
# Returns nothing.
|
12
|
+
def self.load_from_gems
|
13
|
+
gem_directories.each do |directory|
|
14
|
+
path = directory + 'puppet-lint/plugins'
|
15
|
+
next unless path.directory?
|
16
|
+
|
17
|
+
Dir["#{path}/**/*.rb"].each do |file|
|
18
|
+
load(file)
|
20
19
|
end
|
21
20
|
end
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
# Public: Load the puppet-lint spec_helper.rb
|
24
|
+
#
|
25
|
+
# Returns nothings.
|
26
|
+
def self.load_spec_helper
|
27
|
+
gemspec = gemspecs.find { |spec| spec.name == 'puppet-lint' }
|
28
|
+
load(Pathname.new(gemspec.full_gem_path) + 'spec/spec_helper.rb')
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
class << self
|
32
|
+
private
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
false
|
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 ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase)
|
62
60
|
end
|
61
|
+
false
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
else
|
73
|
-
[]
|
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'
|
74
71
|
end
|
72
|
+
else
|
73
|
+
[]
|
75
74
|
end
|
76
75
|
end
|
77
76
|
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
|
+
}
|