1
1
PuppetLint . new_check ( :check_unsafe_interpolations ) do
2
- COMMANDS = Array [ 'command' , 'onlyif' , 'unless' ]
3
- INTERPOLATED_STRINGS = Array [ :DQPRE , :DQMID ]
4
- USELESS_CHARS = Array [ :WHITESPACE , :COMMA ]
2
+ COMMANDS = [ 'command' , 'onlyif' , 'unless' ] . freeze
3
+ INTERPOLATED_STRINGS = [ :DQPRE , :DQMID ] . freeze
4
+ USELESS_CHARS = [ :WHITESPACE , :COMMA ] . freeze
5
5
def check
6
6
# Gather any exec commands' resources into an array
7
7
exec_resources = resource_indexes . map { |resource |
8
8
resource_parameters = resource [ :param_tokens ] . map ( &:value )
9
- resource if resource [ :type ] . value == 'exec' && !( COMMANDS & resource_parameters ) . empty ?
9
+ resource if resource [ :type ] . value == 'exec' && !COMMANDS . intersect? ( resource_parameters ) . nil ?
10
10
} . compact
11
11
12
12
# Iterate over title tokens and raise a warning if any are variables
@@ -33,7 +33,7 @@ def check_unsafe_title(title)
33
33
def check_unsafe_interpolations ( command_resources )
34
34
command_resources [ :tokens ] . each do |token |
35
35
# Skip iteration if token isn't a command of type :NAME
36
- next unless COMMANDS . include? ( token . value ) && ( token . type == :NAME || token . type == :UNLESS )
36
+ next unless COMMANDS . include? ( token . value ) && [ :NAME , :UNLESS ] . include? ( token . type )
37
37
# Don't check the command if it is parameterised
38
38
next if parameterised? ( token )
39
39
@@ -106,7 +106,7 @@ def get_exec_titles
106
106
result << tokens [ title_start_idx ..title_end_idx ]
107
107
# Title is in single quotes
108
108
else
109
- tokens_array . concat ( [ tokens [ token_idx ] . next_code_token . next_code_token ] )
109
+ tokens_array . push ( tokens [ token_idx ] . next_code_token . next_code_token )
110
110
111
111
result << tokens_array
112
112
end
0 commit comments