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
@@ -1,173 +1,171 @@
|
|
1
1
|
require 'strscan'
|
2
2
|
|
3
|
-
class PuppetLint
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@results = []
|
24
|
-
@interp_stack = []
|
25
|
-
@segment = []
|
26
|
-
end
|
27
|
-
|
28
|
-
def parse
|
29
|
-
@segment_type = :STRING
|
30
|
-
|
31
|
-
until scanner.eos?
|
32
|
-
if scanner.match?(START_INTERP_PATTERN)
|
33
|
-
start_interp
|
34
|
-
elsif !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
|
35
|
-
read_char
|
36
|
-
elsif scanner.match?(END_INTERP_PATTERN)
|
37
|
-
end_interp
|
38
|
-
elsif unenclosed_variable?
|
39
|
-
unenclosed_variable
|
40
|
-
elsif scanner.match?(END_STRING_PATTERN)
|
41
|
-
end_string
|
42
|
-
break if interp_stack.empty?
|
43
|
-
elsif scanner.match?(ESC_DQUOTE_PATTERN)
|
44
|
-
@segment << scanner.scan(ESC_DQUOTE_PATTERN)
|
45
|
-
else
|
46
|
-
read_char
|
47
|
-
end
|
48
|
-
end
|
3
|
+
class PuppetLint::Lexer
|
4
|
+
# Internal: A class for slurping strings from a Puppet manifest.
|
5
|
+
class StringSlurper
|
6
|
+
attr_accessor :scanner
|
7
|
+
attr_accessor :results
|
8
|
+
attr_accessor :interp_stack
|
9
|
+
|
10
|
+
START_INTERP_PATTERN = %r{\$\{}.freeze
|
11
|
+
END_INTERP_PATTERN = %r{\}}.freeze
|
12
|
+
END_STRING_PATTERN = %r{(\A|[^\\])(\\\\)*"}.freeze
|
13
|
+
UNENC_VAR_PATTERN = %r{(\A|[^\\])\$(::)?(\w+(-\w+)*::)*\w+(-\w+)*}.freeze
|
14
|
+
ESC_DQUOTE_PATTERN = %r{\\+"}.freeze
|
15
|
+
LBRACE_PATTERN = %r{\{}.freeze
|
16
|
+
|
17
|
+
def initialize(string)
|
18
|
+
@scanner = StringScanner.new(string)
|
19
|
+
@results = []
|
20
|
+
@interp_stack = []
|
21
|
+
@segment = []
|
22
|
+
end
|
49
23
|
|
50
|
-
|
24
|
+
def parse
|
25
|
+
@segment_type = :STRING
|
51
26
|
|
52
|
-
|
27
|
+
until scanner.eos?
|
28
|
+
if scanner.match?(START_INTERP_PATTERN)
|
29
|
+
start_interp
|
30
|
+
elsif !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
|
31
|
+
read_char
|
32
|
+
elsif scanner.match?(END_INTERP_PATTERN)
|
33
|
+
end_interp
|
34
|
+
elsif unenclosed_variable?
|
35
|
+
unenclosed_variable
|
36
|
+
elsif scanner.match?(END_STRING_PATTERN)
|
37
|
+
end_string
|
38
|
+
break if interp_stack.empty?
|
39
|
+
elsif scanner.match?(ESC_DQUOTE_PATTERN)
|
40
|
+
@segment << scanner.scan(ESC_DQUOTE_PATTERN)
|
41
|
+
else
|
42
|
+
read_char
|
43
|
+
end
|
53
44
|
end
|
54
45
|
|
55
|
-
|
56
|
-
interp_stack.empty? &&
|
57
|
-
scanner.match?(UNENC_VAR_PATTERN) &&
|
58
|
-
(@segment.last.nil? ? true : !@segment.last.end_with?('\\'))
|
59
|
-
end
|
46
|
+
raise UnterminatedStringError if results.empty? && scanner.matched?
|
60
47
|
|
61
|
-
|
62
|
-
|
63
|
-
end_heredoc_pattern = %r{^\|?\s*-?\s*#{Regexp.escape(heredoc_name)}$}
|
64
|
-
interpolation = heredoc_tag.start_with?('"')
|
65
|
-
|
66
|
-
@segment_type = :HEREDOC
|
67
|
-
|
68
|
-
until scanner.eos?
|
69
|
-
if scanner.match?(end_heredoc_pattern)
|
70
|
-
end_heredoc(end_heredoc_pattern)
|
71
|
-
break if interp_stack.empty?
|
72
|
-
elsif interpolation && scanner.match?(START_INTERP_PATTERN)
|
73
|
-
start_interp
|
74
|
-
elsif interpolation && !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
|
75
|
-
read_char
|
76
|
-
elsif interpolation && unenclosed_variable?
|
77
|
-
unenclosed_variable
|
78
|
-
elsif interpolation && scanner.match?(END_INTERP_PATTERN)
|
79
|
-
end_interp
|
80
|
-
else
|
81
|
-
read_char
|
82
|
-
end
|
83
|
-
end
|
48
|
+
results
|
49
|
+
end
|
84
50
|
|
85
|
-
|
86
|
-
|
51
|
+
def unenclosed_variable?
|
52
|
+
interp_stack.empty? &&
|
53
|
+
scanner.match?(UNENC_VAR_PATTERN) &&
|
54
|
+
(@segment.last.nil? ? true : !@segment.last.end_with?('\\'))
|
55
|
+
end
|
87
56
|
|
88
|
-
|
89
|
-
|
57
|
+
def parse_heredoc(heredoc_tag)
|
58
|
+
heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?#{PuppetLint::Lexer::WHITESPACE_RE}*(/.*)?\Z}o, 1]
|
59
|
+
end_heredoc_pattern = %r{^\|?\s*-?\s*#{Regexp.escape(heredoc_name)}$}
|
60
|
+
interpolation = heredoc_tag.start_with?('"')
|
90
61
|
|
91
|
-
|
62
|
+
@segment_type = :HEREDOC
|
92
63
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
64
|
+
until scanner.eos?
|
65
|
+
if scanner.match?(end_heredoc_pattern)
|
66
|
+
end_heredoc(end_heredoc_pattern)
|
67
|
+
break if interp_stack.empty?
|
68
|
+
elsif interpolation && scanner.match?(START_INTERP_PATTERN)
|
69
|
+
start_interp
|
70
|
+
elsif interpolation && !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
|
71
|
+
read_char
|
72
|
+
elsif interpolation && unenclosed_variable?
|
73
|
+
unenclosed_variable
|
74
|
+
elsif interpolation && scanner.match?(END_INTERP_PATTERN)
|
75
|
+
end_interp
|
76
|
+
else
|
77
|
+
read_char
|
98
78
|
end
|
99
79
|
end
|
100
80
|
|
101
|
-
|
102
|
-
|
103
|
-
# StringScanner from Ruby 2.0 onwards supports #charpos which returns
|
104
|
-
# the number of characters and is multibyte character aware.
|
105
|
-
#
|
106
|
-
# Prior to this, Ruby's multibyte character support in Strings was a
|
107
|
-
# bit unusual and neither String#length nor String#split behave as
|
108
|
-
# expected, so we use String#scan to split all the consumed text using
|
109
|
-
# a UTF-8 aware regex and use the length of the result
|
110
|
-
def consumed_chars
|
111
|
-
return scanner.charpos if scanner.respond_to?(:charpos)
|
112
|
-
|
113
|
-
(scanner.pre_match + scanner.matched).scan(%r{.}mu).length
|
114
|
-
end
|
81
|
+
results
|
82
|
+
end
|
115
83
|
|
116
|
-
|
117
|
-
|
118
|
-
read_char
|
119
|
-
return
|
120
|
-
end
|
84
|
+
def read_char
|
85
|
+
@segment << scanner.getch
|
121
86
|
|
122
|
-
|
123
|
-
scanner.skip(START_INTERP_PATTERN)
|
124
|
-
results << [@segment_type, @segment.join]
|
125
|
-
@segment = []
|
126
|
-
else
|
127
|
-
@segment << scanner.scan(START_INTERP_PATTERN)
|
128
|
-
end
|
87
|
+
return if interp_stack.empty?
|
129
88
|
|
89
|
+
case @segment.last
|
90
|
+
when '{'
|
130
91
|
interp_stack.push(true)
|
92
|
+
when '}'
|
93
|
+
interp_stack.pop
|
131
94
|
end
|
95
|
+
end
|
132
96
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
97
|
+
# Get the number of characters consumed by the StringSlurper.
|
98
|
+
#
|
99
|
+
# StringScanner from Ruby 2.0 onwards supports #charpos which returns
|
100
|
+
# the number of characters and is multibyte character aware.
|
101
|
+
#
|
102
|
+
# Prior to this, Ruby's multibyte character support in Strings was a
|
103
|
+
# bit unusual and neither String#length nor String#split behave as
|
104
|
+
# expected, so we use String#scan to split all the consumed text using
|
105
|
+
# a UTF-8 aware regex and use the length of the result
|
106
|
+
def consumed_chars
|
107
|
+
return scanner.charpos if scanner.respond_to?(:charpos)
|
108
|
+
|
109
|
+
(scanner.pre_match + scanner.matched).scan(%r{.}mu).length
|
110
|
+
end
|
140
111
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
else
|
146
|
-
@segment << scanner.scan(END_INTERP_PATTERN)
|
147
|
-
end
|
112
|
+
def start_interp
|
113
|
+
if @segment.last && @segment.last == '\\'
|
114
|
+
read_char
|
115
|
+
return
|
148
116
|
end
|
149
117
|
|
150
|
-
|
151
|
-
|
152
|
-
|
118
|
+
if interp_stack.empty?
|
119
|
+
scanner.skip(START_INTERP_PATTERN)
|
153
120
|
results << [@segment_type, @segment.join]
|
154
|
-
results << [:UNENC_VAR, scanner.scan(UNENC_VAR_PATTERN)]
|
155
121
|
@segment = []
|
122
|
+
else
|
123
|
+
@segment << scanner.scan(START_INTERP_PATTERN)
|
156
124
|
end
|
157
125
|
|
158
|
-
|
159
|
-
|
160
|
-
|
126
|
+
interp_stack.push(true)
|
127
|
+
end
|
128
|
+
|
129
|
+
def end_interp
|
130
|
+
if interp_stack.empty?
|
131
|
+
@segment << scanner.scan(END_INTERP_PATTERN)
|
132
|
+
return
|
133
|
+
else
|
134
|
+
interp_stack.pop
|
161
135
|
end
|
162
136
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
137
|
+
if interp_stack.empty?
|
138
|
+
results << [:INTERP, @segment.join]
|
139
|
+
@segment = []
|
140
|
+
scanner.skip(END_INTERP_PATTERN)
|
141
|
+
else
|
142
|
+
@segment << scanner.scan(END_INTERP_PATTERN)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def unenclosed_variable
|
147
|
+
read_char if scanner.match?(%r{.\$})
|
148
|
+
|
149
|
+
results << [@segment_type, @segment.join]
|
150
|
+
results << [:UNENC_VAR, scanner.scan(UNENC_VAR_PATTERN)]
|
151
|
+
@segment = []
|
152
|
+
end
|
153
|
+
|
154
|
+
def end_heredoc(pattern)
|
155
|
+
results << [:HEREDOC, @segment.join]
|
156
|
+
results << [:HEREDOC_TERM, scanner.scan(pattern)]
|
157
|
+
end
|
158
|
+
|
159
|
+
def end_string
|
160
|
+
if interp_stack.empty?
|
161
|
+
@segment << scanner.scan(END_STRING_PATTERN).gsub!(%r{"\Z}, '')
|
162
|
+
results << [@segment_type, @segment.join]
|
163
|
+
else
|
164
|
+
@segment << scanner.scan(END_STRING_PATTERN)
|
170
165
|
end
|
171
166
|
end
|
172
167
|
end
|
173
168
|
end
|
169
|
+
|
170
|
+
# Internal: An error thrown when an unterminated string is encountered.
|
171
|
+
class PuppetLint::Lexer::StringSlurper::UnterminatedStringError < StandardError; end
|