puppet-lint 3.4.0 → 4.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet-lint/bin.rb +7 -11
- data/lib/puppet-lint/checkplugin.rb +4 -8
- data/lib/puppet-lint/checks.rb +7 -9
- data/lib/puppet-lint/configuration.rb +2 -2
- data/lib/puppet-lint/data.rb +35 -39
- data/lib/puppet-lint/lexer/string_slurper.rb +2 -3
- data/lib/puppet-lint/lexer/token.rb +6 -5
- data/lib/puppet-lint/lexer.rb +35 -38
- data/lib/puppet-lint/monkeypatches.rb +4 -4
- data/lib/puppet-lint/optparser.rb +1 -1
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +1 -0
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +2 -4
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +2 -2
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +1 -1
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -5
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +8 -9
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +32 -34
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +2 -2
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -6
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +1 -1
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +3 -5
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +2 -2
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +6 -6
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +4 -4
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +4 -4
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +4 -5
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +4 -4
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +2 -2
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +8 -7
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +3 -3
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +2 -2
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +1 -0
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +2 -1
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +9 -9
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +2 -2
- data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +6 -6
- data/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +106 -105
- data/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +3 -2
- data/lib/puppet-lint/plugins.rb +3 -4
- data/lib/puppet-lint/report/codeclimate.rb +3 -2
- data/lib/puppet-lint/report/github.rb +1 -0
- data/lib/puppet-lint/tasks/puppet-lint.rb +7 -26
- data/lib/puppet-lint/tasks/release_test.rb +4 -4
- data/lib/puppet-lint/version.rb +1 -1
- data/lib/puppet-lint.rb +5 -3
- data/rubocop_baseline.yml +3 -440
- data/spec/spec_helper.rb +3 -2
- data/spec/spec_helper_acceptance_local.rb +1 -1
- data/spec/unit/puppet-lint/bin_spec.rb +12 -2
- data/spec/unit/puppet-lint/configuration_spec.rb +14 -14
- data/spec/unit/puppet-lint/lexer/string_slurper_spec.rb +3 -5
- data/spec/unit/puppet-lint/lexer_spec.rb +10 -11
- data/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +2 -2
- data/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +5 -5
- data/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +1 -1
- data/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +1 -1
- data/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb +0 -2
- data/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +1 -3
- data/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +16 -0
- data/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +1 -0
- metadata +5 -5
@@ -5,7 +5,7 @@
|
|
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]
|
8
|
+
next unless class_idx[:inherited_token]&.value&.end_with?('::params')
|
9
9
|
|
10
10
|
notify(
|
11
11
|
:warning,
|
@@ -18,4 +18,4 @@ PuppetLint.new_check(:class_inherits_from_params_class) do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
-
PuppetLint.configuration.send(
|
21
|
+
PuppetLint.configuration.send(:disable_class_inherits_from_params_class)
|
@@ -2,18 +2,18 @@
|
|
2
2
|
# defined inside another class.
|
3
3
|
#
|
4
4
|
# https://puppet.com/docs/puppet/latest/style_guide.html#nested-classes-or-defined-types
|
5
|
+
CLASS_DEFINE_TOKENS = Set[:CLASS, :DEFINE]
|
5
6
|
PuppetLint.new_check(:nested_classes_or_defines) do
|
6
|
-
TOKENS = Set[:CLASS, :DEFINE]
|
7
|
-
|
8
7
|
def check
|
9
8
|
class_indexes.each do |class_idx|
|
10
9
|
# Skip the first token so that we don't pick up the first :CLASS
|
11
|
-
class_tokens = class_idx[:tokens][1
|
10
|
+
class_tokens = class_idx[:tokens][1..]
|
12
11
|
|
13
12
|
class_tokens.each do |token|
|
14
|
-
next unless
|
13
|
+
next unless CLASS_DEFINE_TOKENS.include?(token.type)
|
15
14
|
next if token.next_code_token.type == :LBRACE
|
16
|
-
|
15
|
+
|
16
|
+
type = (token.type == :CLASS) ? 'class' : 'defined type'
|
17
17
|
|
18
18
|
notify(
|
19
19
|
:warning,
|
@@ -11,13 +11,14 @@ PuppetLint.new_check(:parameter_order) do
|
|
11
11
|
paren_stack = []
|
12
12
|
hash_or_array_stack = []
|
13
13
|
class_idx[:param_tokens].each_with_index do |token, i|
|
14
|
-
|
14
|
+
case token.type
|
15
|
+
when :LPAREN
|
15
16
|
paren_stack.push(true)
|
16
|
-
|
17
|
+
when :RPAREN
|
17
18
|
paren_stack.pop
|
18
|
-
|
19
|
+
when :LBRACE, :LBRACK
|
19
20
|
hash_or_array_stack.push(true)
|
20
|
-
|
21
|
+
when :RBRACE, :RBRACK
|
21
22
|
hash_or_array_stack.pop
|
22
23
|
end
|
23
24
|
|
@@ -34,8 +35,8 @@ PuppetLint.new_check(:parameter_order) do
|
|
34
35
|
message: msg,
|
35
36
|
line: token.line,
|
36
37
|
column: token.column,
|
37
|
-
description: 'Test the manifest tokens for any parameterised classes or defined types that take '\
|
38
|
-
|
38
|
+
description: 'Test the manifest tokens for any parameterised classes or defined types that take ' \
|
39
|
+
'parameters and record a warning if there are any optional parameters listed before required parameters.',
|
39
40
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order-of-parameters',
|
40
41
|
)
|
41
42
|
end
|
@@ -58,9 +59,7 @@ PuppetLint.new_check(:parameter_order) do
|
|
58
59
|
data_type = token.prev_token_of(:TYPE, skip_blocks: true)
|
59
60
|
return false if data_type && data_type.value == 'Optional'
|
60
61
|
|
61
|
-
if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
|
62
|
-
return !(token.prev_code_token && token.prev_code_token.type == :EQUALS)
|
63
|
-
end
|
62
|
+
return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
|
64
63
|
|
65
64
|
false
|
66
65
|
end
|
@@ -5,35 +5,35 @@
|
|
5
5
|
# not.
|
6
6
|
#
|
7
7
|
# https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN]
|
8
|
+
DEFAULT_SCOPE_VARS = Set[
|
9
|
+
'name',
|
10
|
+
'title',
|
11
|
+
'module_name',
|
12
|
+
'environment',
|
13
|
+
'clientcert',
|
14
|
+
'clientversion',
|
15
|
+
'servername',
|
16
|
+
'serverip',
|
17
|
+
'serverversion',
|
18
|
+
'caller_module_name',
|
19
|
+
'alias',
|
20
|
+
'audit',
|
21
|
+
'before',
|
22
|
+
'loglevel',
|
23
|
+
'noop',
|
24
|
+
'notify',
|
25
|
+
'require',
|
26
|
+
'schedule',
|
27
|
+
'stage',
|
28
|
+
'subscribe',
|
29
|
+
'tag',
|
30
|
+
'facts',
|
31
|
+
'trusted',
|
32
|
+
'server_facts',
|
33
|
+
]
|
34
|
+
POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN]
|
36
35
|
|
36
|
+
PuppetLint.new_check(:variable_scope) do
|
37
37
|
def check
|
38
38
|
variables_in_scope = DEFAULT_SCOPE_VARS.clone
|
39
39
|
|
@@ -93,7 +93,7 @@ PuppetLint.new_check(:variable_scope) do
|
|
93
93
|
end_token = nil
|
94
94
|
brace_depth = 0
|
95
95
|
|
96
|
-
tokens[start_idx
|
96
|
+
tokens[start_idx..].each do |sub_token|
|
97
97
|
case sub_token.type
|
98
98
|
when :LBRACE
|
99
99
|
brace_depth += 1
|
@@ -117,9 +117,7 @@ PuppetLint.new_check(:variable_scope) do
|
|
117
117
|
|
118
118
|
msg = 'top-scope variable being used without an explicit namespace'
|
119
119
|
referenced_variables.each do |token|
|
120
|
-
|
121
|
-
next if future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, ''))
|
122
|
-
end
|
120
|
+
next if !future_parser_scopes[token.line].nil? && future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, ''))
|
123
121
|
|
124
122
|
next if token.value.include?('::')
|
125
123
|
next if %r{^(facts|trusted)\[.+\]}.match?(token.value)
|
@@ -132,8 +130,8 @@ PuppetLint.new_check(:variable_scope) do
|
|
132
130
|
line: token.line,
|
133
131
|
column: token.column,
|
134
132
|
description: 'Test the manifest tokens for any variables that are referenced in the manifest. ' \
|
135
|
-
|
136
|
-
|
133
|
+
'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \
|
134
|
+
'check that they have been defined in the local scope and record a warning for each variable that has not.',
|
137
135
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables',
|
138
136
|
)
|
139
137
|
end
|
@@ -10,7 +10,7 @@ PuppetLint.new_check(:case_without_default) do
|
|
10
10
|
next unless tokens[token_idx].type == :CASE
|
11
11
|
|
12
12
|
depth = 0
|
13
|
-
tokens[(token_idx + 1)
|
13
|
+
tokens[(token_idx + 1)..].each_index do |case_token_idx|
|
14
14
|
idx = case_token_idx + token_idx + 1
|
15
15
|
if tokens[idx].type == :LBRACE
|
16
16
|
depth += 1
|
@@ -27,7 +27,7 @@ PuppetLint.new_check(:case_without_default) do
|
|
27
27
|
case_indexes.each_with_index do |kase, kase_index|
|
28
28
|
case_tokens = tokens[kase[:start]..kase[:end]]
|
29
29
|
|
30
|
-
case_indexes[(kase_index + 1)
|
30
|
+
case_indexes[(kase_index + 1)..].each do |successor_kase|
|
31
31
|
case_tokens -= tokens[successor_kase[:start]..successor_kase[:end]]
|
32
32
|
end
|
33
33
|
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# record a warning for each instance found.
|
4
4
|
#
|
5
5
|
# https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private
|
6
|
-
|
7
|
-
|
8
|
-
WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT]
|
6
|
+
COMMENT_TOKENS = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT]
|
7
|
+
WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT]
|
9
8
|
|
9
|
+
PuppetLint.new_check(:documentation) do
|
10
10
|
def check
|
11
11
|
(class_indexes + defined_type_indexes).each do |item_idx|
|
12
12
|
comment_token = find_comment_token(item_idx[:tokens].first)
|
@@ -25,9 +25,9 @@ PuppetLint.new_check(:documentation) do
|
|
25
25
|
message: "#{type} not documented",
|
26
26
|
line: first_token.line,
|
27
27
|
column: first_token.column,
|
28
|
-
description: 'Check the manifest tokens for any class or defined type that does not '\
|
29
|
-
|
30
|
-
|
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
31
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private',
|
32
32
|
)
|
33
33
|
end
|
@@ -40,6 +40,7 @@ PuppetLint.new_check(:documentation) do
|
|
40
40
|
while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type)
|
41
41
|
newlines += 1 if prev_token.type == :NEWLINE
|
42
42
|
break if newlines > 1
|
43
|
+
|
43
44
|
prev_token = prev_token.prev_token
|
44
45
|
end
|
45
46
|
|
@@ -7,7 +7,7 @@ PuppetLint.new_check(:unquoted_node_name) do
|
|
7
7
|
node_tokens = tokens.select { |token| token.type == :NODE }
|
8
8
|
node_tokens.each do |node|
|
9
9
|
node_token_idx = tokens.index(node)
|
10
|
-
node_lbrace_tok = tokens[node_token_idx
|
10
|
+
node_lbrace_tok = tokens[node_token_idx..].find { |token| token.type == :LBRACE }
|
11
11
|
if node_lbrace_tok.nil?
|
12
12
|
notify(
|
13
13
|
:error,
|
@@ -21,8 +21,8 @@ PuppetLint.new_check(:ensure_first_param) do
|
|
21
21
|
line: ensure_token.line,
|
22
22
|
column: ensure_token.column,
|
23
23
|
resource: resource,
|
24
|
-
description: 'Check the tokens of each resource instance for an ensure parameter and if '\
|
25
|
-
|
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
26
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering',
|
27
27
|
)
|
28
28
|
end
|
@@ -37,9 +37,7 @@ PuppetLint.new_check(:ensure_first_param) do
|
|
37
37
|
|
38
38
|
ensure_param_comma_token = ensure_param_name_token.next_token_of([:COMMA, :SEMIC])
|
39
39
|
|
40
|
-
if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil?
|
41
|
-
raise PuppetLint::NoFix
|
42
|
-
end
|
40
|
+
raise PuppetLint::NoFix if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil?
|
43
41
|
|
44
42
|
first_param_name_idx = tokens.index(first_param_name_token)
|
45
43
|
first_param_comma_idx = tokens.index(first_param_comma_token)
|
@@ -21,8 +21,8 @@ PuppetLint.new_check(:ensure_not_symlink_target) do
|
|
21
21
|
column: value_token.column,
|
22
22
|
param_token: ensure_token,
|
23
23
|
value_token: value_token,
|
24
|
-
description: 'Check the tokens of each File resource instance for an ensure parameter and '\
|
25
|
-
|
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
26
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links',
|
27
27
|
)
|
28
28
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
# not a 4 digit octal value (0755) or a symbolic mode ('o=rwx,g+r').
|
4
4
|
#
|
5
5
|
# https://puppet.com/docs/puppet/latest/style_guide.html#file-modes
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze
|
6
|
+
MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze
|
7
|
+
SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze
|
8
|
+
IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME]
|
9
|
+
MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze
|
11
10
|
|
11
|
+
PuppetLint.new_check(:file_mode) do
|
12
12
|
def check
|
13
13
|
resource_indexes.each do |resource|
|
14
14
|
next unless resource[:type].value == 'file' || resource[:type].value == 'concat'
|
@@ -30,7 +30,7 @@ PuppetLint.new_check(:file_mode) do
|
|
30
30
|
column: value_token.column,
|
31
31
|
token: value_token,
|
32
32
|
description: 'Check the tokens of each File resource instance for a mode parameter and if found, ' \
|
33
|
-
|
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
34
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes',
|
35
35
|
)
|
36
36
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# not a quoted string.
|
4
4
|
#
|
5
5
|
# https://puppet.com/docs/puppet/latest/style_guide.html#file-modes
|
6
|
-
|
7
|
-
TOKEN_TYPES = Set[:NAME, :NUMBER]
|
6
|
+
TOKEN_TYPES = Set[:NAME, :NUMBER]
|
8
7
|
|
8
|
+
PuppetLint.new_check(:unquoted_file_mode) do
|
9
9
|
def check
|
10
10
|
resource_indexes.each do |resource|
|
11
11
|
next unless resource[:type].value == 'file' || resource[:type].value == 'concat'
|
@@ -23,8 +23,8 @@ PuppetLint.new_check(:unquoted_file_mode) do
|
|
23
23
|
line: value_token.line,
|
24
24
|
column: value_token.column,
|
25
25
|
token: value_token,
|
26
|
-
description: 'Check the tokens of each File resource instance for a mode parameter '\
|
27
|
-
|
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
28
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes',
|
29
29
|
)
|
30
30
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# each instance found.
|
4
4
|
#
|
5
5
|
# https://puppet.com/docs/puppet/latest/style_guide.html#quoting
|
6
|
-
|
7
|
-
ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze
|
6
|
+
ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze
|
8
7
|
|
8
|
+
PuppetLint.new_check(:double_quoted_strings) do
|
9
9
|
def check
|
10
10
|
invalid_tokens = tokens.select do |token|
|
11
11
|
token.type == :STRING &&
|
@@ -19,8 +19,8 @@ PuppetLint.new_check(:double_quoted_strings) do
|
|
19
19
|
line: token.line,
|
20
20
|
column: token.column,
|
21
21
|
token: token,
|
22
|
-
description: 'Check the manifest tokens for any double quoted strings that don\'t '\
|
23
|
-
|
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
24
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
|
25
25
|
)
|
26
26
|
end
|
@@ -2,9 +2,9 @@
|
|
2
2
|
# a single variable only and record a warning for each instance found.
|
3
3
|
#
|
4
4
|
# https://puppet.com/docs/puppet/latest/style_guide.html#quoting
|
5
|
-
|
6
|
-
VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
5
|
+
VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
7
6
|
|
7
|
+
PuppetLint.new_check(:only_variable_string) do
|
8
8
|
def check
|
9
9
|
tokens.each_with_index do |start_token, start_token_idx|
|
10
10
|
next unless start_token.type == :DQPRE && start_token.value == ''
|
@@ -20,9 +20,8 @@ PuppetLint.new_check(:only_variable_string) do
|
|
20
20
|
eos_offset += 3
|
21
21
|
when :DQPOST
|
22
22
|
if eos_token.value == ''
|
23
|
-
if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW
|
24
|
-
|
25
|
-
end
|
23
|
+
break if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW
|
24
|
+
|
26
25
|
notify(
|
27
26
|
:warning,
|
28
27
|
message: 'string containing only a variable',
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# found.
|
4
4
|
#
|
5
5
|
# No style guide reference
|
6
|
-
|
7
|
-
|
8
|
-
BOOLEANS = Set['true', 'false']
|
6
|
+
STRING_TYPES = Set[:STRING, :SSTRING]
|
7
|
+
BOOLEANS = Set['true', 'false']
|
9
8
|
|
9
|
+
PuppetLint.new_check(:quoted_booleans) do
|
10
10
|
def check
|
11
11
|
invalid_tokens = tokens.select do |token|
|
12
12
|
STRING_TYPES.include?(token.type) && BOOLEANS.include?(token.value)
|
@@ -29,4 +29,4 @@ PuppetLint.new_check(:quoted_booleans) do
|
|
29
29
|
problem[:token].type = problem[:token].value.upcase.to_sym
|
30
30
|
end
|
31
31
|
end
|
32
|
-
PuppetLint.configuration.send(
|
32
|
+
PuppetLint.configuration.send(:disable_quoted_booleans)
|
@@ -14,8 +14,8 @@ PuppetLint.new_check(:single_quote_string_with_variables) do
|
|
14
14
|
message: 'single quoted string containing a variable found',
|
15
15
|
line: token.line,
|
16
16
|
column: token.column,
|
17
|
-
description: 'Check the manifest tokens for any single quoted strings containing '\
|
18
|
-
|
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
19
|
help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting',
|
20
20
|
)
|
21
21
|
end
|
@@ -6,14 +6,14 @@ require 'strscan'
|
|
6
6
|
# found.
|
7
7
|
#
|
8
8
|
# https://puppet.com/docs/puppet/latest/style_guide.html#quoting
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
]
|
9
|
+
STRING_TOKEN_TYPES = Set[
|
10
|
+
:DQMID,
|
11
|
+
:DQPOST,
|
12
|
+
:HEREDOC_MID,
|
13
|
+
:HEREDOC_POST,
|
14
|
+
]
|
16
15
|
|
16
|
+
PuppetLint.new_check(:variables_not_enclosed) do
|
17
17
|
def check
|
18
18
|
invalid_tokens = tokens.select do |token|
|
19
19
|
token.type == :UNENC_VARIABLE
|
@@ -74,6 +74,7 @@ PuppetLint.new_check(:variables_not_enclosed) do
|
|
74
74
|
var_token.value = var_name
|
75
75
|
|
76
76
|
return if str_token.nil?
|
77
|
+
|
77
78
|
str_token.value = "-#{text}#{str_token.value}"
|
78
79
|
end
|
79
80
|
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# record a warning for each instance found.
|
3
3
|
#
|
4
4
|
# No style guide reference
|
5
|
-
|
6
|
-
VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
5
|
+
VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
7
6
|
|
7
|
+
PuppetLint.new_check(:variable_contains_dash) do
|
8
8
|
def check
|
9
9
|
invalid_tokens = tokens.select do |token|
|
10
10
|
VARIABLE_DASH_TYPES.include?(token.type)
|
11
11
|
end
|
12
12
|
|
13
13
|
invalid_tokens.each do |token|
|
14
|
-
next unless
|
14
|
+
next unless token.value.gsub(%r{\[.+?\]}, '').include?('-')
|
15
15
|
|
16
16
|
notify(
|
17
17
|
:warning,
|
@@ -2,9 +2,9 @@
|
|
2
2
|
# letter and record a warning for each instance found.
|
3
3
|
#
|
4
4
|
# No style guide reference
|
5
|
-
|
6
|
-
VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
5
|
+
VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
|
7
6
|
|
7
|
+
PuppetLint.new_check(:variable_is_lowercase) do
|
8
8
|
def check
|
9
9
|
invalid_tokens = tokens.select do |token|
|
10
10
|
VARIABLE_LOWERCASE_TYPES.include?(token.type)
|
@@ -9,8 +9,9 @@ PuppetLint.new_check(:'80chars') do
|
|
9
9
|
result = PuppetLint::LineLengthCheck.check(idx + 1, line, 80)
|
10
10
|
|
11
11
|
next if result.nil?
|
12
|
+
|
12
13
|
notify(*result)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
16
|
-
PuppetLint.configuration.send(
|
17
|
+
PuppetLint.configuration.send(:disable_80chars)
|
@@ -2,9 +2,9 @@
|
|
2
2
|
# are not aligned with other arrows in that grouping.
|
3
3
|
#
|
4
4
|
# https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace
|
5
|
-
|
6
|
-
COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT]
|
5
|
+
COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT]
|
7
6
|
|
7
|
+
PuppetLint.new_check(:arrow_alignment) do
|
8
8
|
def check
|
9
9
|
resource_indexes.each do |res_idx|
|
10
10
|
arrow_column = [0]
|
@@ -24,7 +24,8 @@ PuppetLint.new_check(:arrow_alignment) do
|
|
24
24
|
next if resource_tokens[first_arrow].line == resource_tokens[last_arrow].line
|
25
25
|
|
26
26
|
resource_tokens.each do |token|
|
27
|
-
|
27
|
+
case token.type
|
28
|
+
when :FARROW
|
28
29
|
param_token = token.prev_code_token
|
29
30
|
|
30
31
|
if param_token.type == :DQPOST
|
@@ -54,17 +55,15 @@ PuppetLint.new_check(:arrow_alignment) do
|
|
54
55
|
this_arrow_column += 1
|
55
56
|
end
|
56
57
|
|
57
|
-
if arrow_column[level_idx] < this_arrow_column
|
58
|
-
arrow_column[level_idx] = this_arrow_column
|
59
|
-
end
|
58
|
+
arrow_column[level_idx] = this_arrow_column if arrow_column[level_idx] < this_arrow_column
|
60
59
|
|
61
60
|
(level_tokens[level_idx] ||= []) << token
|
62
|
-
|
61
|
+
when :LBRACE
|
63
62
|
level_idx += 1
|
64
63
|
arrow_column << 0
|
65
64
|
level_tokens[level_idx] ||= []
|
66
65
|
param_column << nil
|
67
|
-
|
66
|
+
when :RBRACE, :SEMIC
|
68
67
|
if (level_tokens[level_idx] ||= []).map(&:line).uniq.length > 1
|
69
68
|
level_tokens[level_idx].each do |arrow_tok|
|
70
69
|
next if arrow_tok.column == arrow_column[level_idx] || level_tokens[level_idx].size == 1
|
@@ -117,7 +116,8 @@ PuppetLint.new_check(:arrow_alignment) do
|
|
117
116
|
new_ws_len += (problem[:arrow_column] - problem[:token].column)
|
118
117
|
end
|
119
118
|
|
120
|
-
raise PuppetLint::NoFix if new_ws_len
|
119
|
+
raise PuppetLint::NoFix if new_ws_len.negative?
|
120
|
+
|
121
121
|
new_ws = ' ' * new_ws_len
|
122
122
|
|
123
123
|
if problem[:token].prev_token.type == :WHITESPACE
|
@@ -2,9 +2,9 @@
|
|
2
2
|
# characters and record an error for each instance found.
|
3
3
|
#
|
4
4
|
# https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace
|
5
|
-
|
6
|
-
WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
|
5
|
+
WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
|
7
6
|
|
7
|
+
PuppetLint.new_check(:hard_tabs) do
|
8
8
|
def check
|
9
9
|
invalid_tokens = tokens.select do |token|
|
10
10
|
WHITESPACE_TYPES.include?(token.type) && token.value.include?("\t")
|
@@ -18,12 +18,12 @@ class PuppetLint::LineLengthCheck
|
|
18
18
|
|
19
19
|
[
|
20
20
|
:warning,
|
21
|
-
message: "line has more than #{character_count} characters",
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
27
|
]
|
28
28
|
end
|
29
29
|
end
|