puppet-lint-trailing_comma-check 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa2a36ca4307710331baaa180b0791ee63dcd591
|
4
|
+
data.tar.gz: d3444472a003019d87de2945c84c9f96f5eb1769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d235a2f71f944e22639ff157ddd7faada07d2ec6c92de801cf6de610ee576e9f09112d113aabecf3bc5fbb3495fb61ba3ff47386a30ab425fcb630a20c7d2c49
|
7
|
+
data.tar.gz: 066b977847270a699e830fe1b0f656415cfcd6997c15c9f76f4ba8185c8fd1c59797ec835413b8b5c3ee1214fa8a927ba4f4494b662f168c87fd27b60bf28b74
|
@@ -1,44 +1,76 @@
|
|
1
1
|
PuppetLint.new_check(:trailing_comma) do
|
2
2
|
def array_indexes
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
@array_indexes ||= Proc.new do
|
4
|
+
arrays = []
|
5
|
+
tokens.each_with_index do |token, token_idx|
|
6
|
+
if token.type == :LBRACK
|
7
|
+
real_idx = 0
|
8
|
+
tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
|
9
|
+
real_idx = token_idx + 1 + cur_token_idx
|
10
|
+
break if cur_token.type == :RBRACK
|
11
|
+
end
|
12
|
+
|
13
|
+
arrays << {
|
14
|
+
:start => token_idx,
|
15
|
+
:end => real_idx,
|
16
|
+
:tokens => tokens[token_idx..real_idx],
|
17
|
+
}
|
10
18
|
end
|
19
|
+
end
|
20
|
+
arrays
|
21
|
+
end.call
|
22
|
+
end
|
11
23
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
def hash_indexes
|
25
|
+
@hash_indexes ||= Proc.new do
|
26
|
+
hashes = []
|
27
|
+
tokens.each_with_index do |token, token_idx|
|
28
|
+
next unless token.prev_code_token
|
29
|
+
next unless [:EQUALS, :ISEQUAL, :FARROW, :LPAREN].include? token.prev_code_token.type
|
30
|
+
if token.type == :LBRACE
|
31
|
+
level = 0
|
32
|
+
real_idx = 0
|
33
|
+
tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
|
34
|
+
real_idx = token_idx + 1 + cur_token_idx
|
35
|
+
|
36
|
+
level += 1 if cur_token.type == :LBRACE
|
37
|
+
level -= 1 if cur_token.type == :RBRACE
|
38
|
+
break if level < 0
|
39
|
+
end
|
40
|
+
|
41
|
+
hashes << {
|
42
|
+
:start => token_idx,
|
43
|
+
:end => real_idx,
|
44
|
+
:tokens => tokens[token_idx..real_idx],
|
45
|
+
}
|
46
|
+
end
|
17
47
|
end
|
18
|
-
|
19
|
-
|
48
|
+
hashes
|
49
|
+
end.call
|
20
50
|
end
|
21
51
|
|
22
52
|
def defaults_indexes
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
53
|
+
@defaults_indexes ||= Proc.new do
|
54
|
+
defaults = []
|
55
|
+
tokens.each_with_index do |token, token_idx|
|
56
|
+
if token.type == :CLASSREF && token.next_code_token && \
|
57
|
+
token.next_code_token.type == :LBRACE
|
58
|
+
real_idx = 0
|
28
59
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
60
|
+
tokens[token_idx+1..-1].each_with_index do |cur_token, cur_token_idx|
|
61
|
+
real_idx = token_idx + 1 + cur_token_idx
|
62
|
+
break if cur_token.type == :RBRACE
|
63
|
+
end
|
33
64
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
65
|
+
defaults << {
|
66
|
+
:start => token_idx,
|
67
|
+
:end => real_idx,
|
68
|
+
:tokens => tokens[token_idx..real_idx],
|
69
|
+
}
|
70
|
+
end
|
39
71
|
end
|
40
|
-
|
41
|
-
|
72
|
+
defaults
|
73
|
+
end.call
|
42
74
|
end
|
43
75
|
|
44
76
|
def check_elem(elem, except_type)
|
@@ -67,6 +99,11 @@ PuppetLint.new_check(:trailing_comma) do
|
|
67
99
|
check_elem(array, :LBRACK)
|
68
100
|
end
|
69
101
|
|
102
|
+
# Hashes
|
103
|
+
hash_indexes.each do |hash|
|
104
|
+
check_elem(hash, :LBRACE)
|
105
|
+
end
|
106
|
+
|
70
107
|
# Defaults
|
71
108
|
defaults_indexes.each do |defaults|
|
72
109
|
check_elem(defaults, :LBRACE)
|
@@ -41,6 +41,14 @@ describe 'trailing_comma' do
|
|
41
41
|
owner => root,
|
42
42
|
group => '0',
|
43
43
|
}
|
44
|
+
|
45
|
+
$foo = {
|
46
|
+
'bar' => {
|
47
|
+
baz => 'abc',
|
48
|
+
bazz => 'def',
|
49
|
+
},
|
50
|
+
'qux' => 'ghi',
|
51
|
+
}
|
44
52
|
EOS
|
45
53
|
}
|
46
54
|
|
@@ -86,11 +94,19 @@ describe 'trailing_comma' do
|
|
86
94
|
owner => root,
|
87
95
|
group => '0'
|
88
96
|
}
|
97
|
+
|
98
|
+
$foo = {
|
99
|
+
'bar' => {
|
100
|
+
baz => 'abc',
|
101
|
+
bazz => 'def'
|
102
|
+
},
|
103
|
+
'qux' => 'ghi'
|
104
|
+
}
|
89
105
|
EOS
|
90
106
|
}
|
91
107
|
|
92
|
-
it 'should detect
|
93
|
-
expect(problems).to have(
|
108
|
+
it 'should detect 6 problems' do
|
109
|
+
expect(problems).to have(6).problems
|
94
110
|
end
|
95
111
|
|
96
112
|
it 'should create warnings' do
|
@@ -98,6 +114,8 @@ describe 'trailing_comma' do
|
|
98
114
|
expect(problems).to contain_warning(msg).on_line(10).in_column(27)
|
99
115
|
expect(problems).to contain_warning(msg).on_line(24).in_column(18)
|
100
116
|
expect(problems).to contain_warning(msg).on_line(33).in_column(23)
|
117
|
+
expect(problems).to contain_warning(msg).on_line(39).in_column(26)
|
118
|
+
expect(problems).to contain_warning(msg).on_line(41).in_column(25)
|
101
119
|
end
|
102
120
|
end
|
103
121
|
end
|
@@ -148,6 +166,14 @@ describe 'trailing_comma' do
|
|
148
166
|
owner => root,
|
149
167
|
group => '0',
|
150
168
|
}
|
169
|
+
|
170
|
+
$foo = {
|
171
|
+
'bar' => {
|
172
|
+
baz => 'abc',
|
173
|
+
bazz => 'def',
|
174
|
+
},
|
175
|
+
'qux' => 'ghi',
|
176
|
+
}
|
151
177
|
EOS
|
152
178
|
}
|
153
179
|
|
@@ -197,11 +223,19 @@ describe 'trailing_comma' do
|
|
197
223
|
owner => root,
|
198
224
|
group => '0'
|
199
225
|
}
|
226
|
+
|
227
|
+
$foo = {
|
228
|
+
'bar' => {
|
229
|
+
baz => 'abc',
|
230
|
+
bazz => 'def'
|
231
|
+
},
|
232
|
+
'qux' => 'ghi'
|
233
|
+
}
|
200
234
|
EOS
|
201
235
|
}
|
202
236
|
|
203
|
-
it 'should detect
|
204
|
-
expect(problems).to have(
|
237
|
+
it 'should detect 6 problems' do
|
238
|
+
expect(problems).to have(6).problems
|
205
239
|
end
|
206
240
|
|
207
241
|
it 'should create a warning' do
|
@@ -209,6 +243,8 @@ describe 'trailing_comma' do
|
|
209
243
|
expect(problems).to contain_fixed(msg).on_line(10).in_column(27)
|
210
244
|
expect(problems).to contain_fixed(msg).on_line(24).in_column(18)
|
211
245
|
expect(problems).to contain_fixed(msg).on_line(33).in_column(23)
|
246
|
+
expect(problems).to contain_fixed(msg).on_line(39).in_column(26)
|
247
|
+
expect(problems).to contain_fixed(msg).on_line(41).in_column(25)
|
212
248
|
end
|
213
249
|
|
214
250
|
it 'should add trailing commas' do
|
@@ -248,6 +284,14 @@ describe 'trailing_comma' do
|
|
248
284
|
owner => root,
|
249
285
|
group => '0',
|
250
286
|
}
|
287
|
+
|
288
|
+
$foo = {
|
289
|
+
'bar' => {
|
290
|
+
baz => 'abc',
|
291
|
+
bazz => 'def',
|
292
|
+
},
|
293
|
+
'qux' => 'ghi',
|
294
|
+
}
|
251
295
|
EOS
|
252
296
|
)
|
253
297
|
end
|