puppet-lint-class_alignment-check 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc0a012b0d80156eaad90609fb62d8f32d580d6acbc5f28e6981d71137fc301
|
4
|
+
data.tar.gz: 72378622329307ce0c0631caebec4fef365fe137b89581bfd01bae1e8bad9537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7750b39ff5ef57ec5fca519a77e1aa0a1b0def9d906814c4c6b2cf096229a8cde51bc75d796e174c4f351e3fe17f4a5baeb79b3649d468e255f88433d3691a2
|
7
|
+
data.tar.gz: 79e3897e36b000f944ebe5d90bbdd671215e2fe94d4a6956a3ddd258fbced0ec4ecd5c8bee7e94b9a69fbc1df88fff411b87872f74babce420f870fc3ac84339
|
@@ -8,8 +8,21 @@ def a_param?(token)
|
|
8
8
|
false
|
9
9
|
elsif token&.prev_code_token&.type == :FARROW
|
10
10
|
false
|
11
|
-
elsif
|
12
|
-
|
11
|
+
elsif %i[DQPRE DQMID].include?(token&.prev_code_token&.type)
|
12
|
+
false
|
13
|
+
elsif token&.type == :VARIABLE
|
14
|
+
count = 0
|
15
|
+
while token&.prev_token
|
16
|
+
token = token.prev_token
|
17
|
+
if %i[LPAREN LBRACK LBRACE].include?(token.type)
|
18
|
+
count += 1
|
19
|
+
elsif %i[RPAREN RBRACK RBRACE].include?(token.type)
|
20
|
+
count -= 1
|
21
|
+
elsif %i[DEFINE CLASS].include?(token.type)
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
true if count == 1
|
13
26
|
end
|
14
27
|
end
|
15
28
|
|
@@ -12,21 +12,16 @@ PuppetLint.new_check(:class_params_newline) do
|
|
12
12
|
tokens = item[:param_tokens]
|
13
13
|
next if tokens.nil?
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
next if
|
19
|
-
|
20
|
-
|
21
|
-
next if tokens[first_param] == tokens[last_param]
|
15
|
+
# Skip if line length < 80 chars
|
16
|
+
first_paren = tokens[0]&.prev_token_of(:LPAREN)
|
17
|
+
last_paren = tokens[-1]&.next_token_of(:RPAREN)
|
18
|
+
next if first_paren.nil?
|
19
|
+
next if last_paren.nil?
|
20
|
+
next if first_paren.line == last_paren.line && last_paren.column < 80
|
22
21
|
|
23
22
|
tokens.each do |token|
|
24
23
|
if token == tokens[-1]
|
25
|
-
rparen = token
|
26
|
-
while rparen&.next_token
|
27
|
-
rparen = rparen.next_token
|
28
|
-
break if rparen.type == :RPAREN
|
29
|
-
end
|
24
|
+
rparen = token.next_token_of(:RPAREN)
|
30
25
|
|
31
26
|
last_code_token = token
|
32
27
|
while last_code_token&.prev_token
|
@@ -46,7 +41,6 @@ PuppetLint.new_check(:class_params_newline) do
|
|
46
41
|
newline: true,
|
47
42
|
newline_indent: item[:tokens][0].column - 1
|
48
43
|
)
|
49
|
-
break
|
50
44
|
end
|
51
45
|
|
52
46
|
next unless a_param?(token)
|
@@ -57,6 +51,7 @@ PuppetLint.new_check(:class_params_newline) do
|
|
57
51
|
next
|
58
52
|
end
|
59
53
|
|
54
|
+
# binding.break
|
60
55
|
notify(
|
61
56
|
:warning,
|
62
57
|
message: "`#{token.to_manifest}` should be in a new line (expected in line #{token.line + 1}, but found it in line #{token.line})",
|
@@ -72,26 +67,37 @@ PuppetLint.new_check(:class_params_newline) do
|
|
72
67
|
|
73
68
|
def fix(problem)
|
74
69
|
token = problem[:token]
|
75
|
-
|
76
|
-
|
77
|
-
token
|
78
|
-
when :RBRACK
|
79
|
-
count = 0
|
80
|
-
while token&.prev_code_token
|
70
|
+
if token.type == :VARIABLE
|
71
|
+
# Integer $db_port
|
72
|
+
if token&.prev_code_token&.type == :TYPE
|
81
73
|
token = token.prev_code_token
|
82
|
-
case token.type
|
83
|
-
when :RBRACK
|
84
|
-
count += 1
|
85
|
-
when :LBRACK
|
86
|
-
count -= 1
|
87
|
-
end
|
88
74
|
|
89
|
-
|
75
|
+
# Variant[Undef, Enum['UNSET'], Stdlib::Port] $db_port
|
76
|
+
elsif token&.prev_code_token&.type == :RBRACK
|
77
|
+
count = 0
|
78
|
+
while token&.prev_code_token
|
79
|
+
token = token.prev_code_token
|
80
|
+
case token.type
|
81
|
+
when :RBRACK
|
82
|
+
count += 1
|
83
|
+
when :LBRACK
|
84
|
+
count -= 1
|
85
|
+
end
|
86
|
+
|
87
|
+
break if count.zero?
|
88
|
+
end
|
89
|
+
token = token.prev_code_token
|
90
90
|
end
|
91
|
-
token = token.prev_code_token
|
92
91
|
end
|
93
92
|
|
94
|
-
|
93
|
+
last_non_whitespace_token = token.prev_token
|
94
|
+
while last_non_whitespace_token&.prev_token
|
95
|
+
break unless %i[WHITESPACE INDENT NEWLINE].include?(last_non_whitespace_token.type)
|
96
|
+
|
97
|
+
last_non_whitespace_token = last_non_whitespace_token.prev_token
|
98
|
+
end
|
99
|
+
|
100
|
+
index = tokens.index(last_non_whitespace_token) + 1
|
95
101
|
tokens.insert(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
|
96
102
|
|
97
103
|
# When there's no space at the beginning of the param
|
@@ -95,44 +95,123 @@ describe 'class_params_newline' do
|
|
95
95
|
let(:code) do
|
96
96
|
<<-END
|
97
97
|
class foo ($foo = 1, $bar = $a) {}
|
98
|
+
class foo ($foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a) {}
|
98
99
|
|
99
100
|
class bar ($foo = 1, $bar = $a,) {}
|
101
|
+
class bar ($foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a,) {}
|
100
102
|
|
101
103
|
class aaa ( $foo = 1, $bar = $a,) {}
|
104
|
+
class aaa ( $foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a,) {}
|
102
105
|
|
103
106
|
class bbb ( $foo = 1, $bar = $a, ) {}
|
107
|
+
class bbb ( $foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a, ) {}
|
104
108
|
|
105
109
|
class ccc ($foo = 1) {}
|
106
110
|
|
107
111
|
class ddd {}
|
112
|
+
|
113
|
+
class eee (
|
114
|
+
$foo = 1,
|
115
|
+
$workers = max($::processorcount, 1),
|
116
|
+
$database_path = $aaa,) inherits sap_zabbix::params { }
|
117
|
+
{ }
|
118
|
+
|
119
|
+
class fff ($foo, $bar=[], $foo, $bar=[], $foo, $bar=[], $listen_ips = [$::ipaddress]) {}
|
120
|
+
|
121
|
+
define ggg ($foo, $bar=[]) {}
|
122
|
+
|
123
|
+
define long_ggg ($foo, $bar=[], $foo, $bar=[], $foo, $bar=[], $foo, $bar=[]) {}
|
124
|
+
|
125
|
+
define asdf ($prefix, $pattern, $expire, $port, $prefix, $pattern, $expire, $port) { }
|
108
126
|
END
|
109
127
|
end
|
110
128
|
|
111
129
|
let(:fixed) do
|
112
130
|
<<-END
|
131
|
+
class foo ($foo = 1, $bar = $a) {}
|
113
132
|
class foo (
|
133
|
+
$foo = 1,
|
134
|
+
$bar = $a,
|
135
|
+
$foo = 1,
|
136
|
+
$bar = $a,
|
114
137
|
$foo = 1,
|
115
138
|
$bar = $a
|
116
139
|
) {}
|
117
140
|
|
141
|
+
class bar ($foo = 1, $bar = $a,) {}
|
118
142
|
class bar (
|
119
143
|
$foo = 1,
|
120
144
|
$bar = $a,
|
145
|
+
$foo = 1,
|
146
|
+
$bar = $a,
|
147
|
+
$foo = 1,
|
148
|
+
$bar = $a,
|
121
149
|
) {}
|
122
150
|
|
151
|
+
class aaa ( $foo = 1, $bar = $a,) {}
|
123
152
|
class aaa (
|
124
153
|
$foo = 1,
|
125
154
|
$bar = $a,
|
155
|
+
$foo = 1,
|
156
|
+
$bar = $a,
|
157
|
+
$foo = 1,
|
158
|
+
$bar = $a,
|
126
159
|
) {}
|
127
160
|
|
161
|
+
class bbb ( $foo = 1, $bar = $a, ) {}
|
128
162
|
class bbb (
|
129
163
|
$foo = 1,
|
130
164
|
$bar = $a,
|
165
|
+
$foo = 1,
|
166
|
+
$bar = $a,
|
167
|
+
$foo = 1,
|
168
|
+
$bar = $a,
|
131
169
|
) {}
|
132
170
|
|
133
171
|
class ccc ($foo = 1) {}
|
134
172
|
|
135
173
|
class ddd {}
|
174
|
+
|
175
|
+
class eee (
|
176
|
+
$foo = 1,
|
177
|
+
$workers = max($::processorcount, 1),
|
178
|
+
$database_path = $aaa,
|
179
|
+
) inherits sap_zabbix::params { }
|
180
|
+
{ }
|
181
|
+
|
182
|
+
class fff (
|
183
|
+
$foo,
|
184
|
+
$bar=[],
|
185
|
+
$foo,
|
186
|
+
$bar=[],
|
187
|
+
$foo,
|
188
|
+
$bar=[],
|
189
|
+
$listen_ips = [$::ipaddress]
|
190
|
+
) {}
|
191
|
+
|
192
|
+
define ggg ($foo, $bar=[]) {}
|
193
|
+
|
194
|
+
define long_ggg (
|
195
|
+
$foo,
|
196
|
+
$bar=[],
|
197
|
+
$foo,
|
198
|
+
$bar=[],
|
199
|
+
$foo,
|
200
|
+
$bar=[],
|
201
|
+
$foo,
|
202
|
+
$bar=[]
|
203
|
+
) {}
|
204
|
+
|
205
|
+
define asdf (
|
206
|
+
$prefix,
|
207
|
+
$pattern,
|
208
|
+
$expire,
|
209
|
+
$port,
|
210
|
+
$prefix,
|
211
|
+
$pattern,
|
212
|
+
$expire,
|
213
|
+
$port
|
214
|
+
) { }
|
136
215
|
END
|
137
216
|
end
|
138
217
|
|