puppet-lint-class_alignment-check 0.2.4 → 0.2.5
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: a097f4f616f220ca1061819f771b0e9553f89d91f2de912b271026d6a1be2640
|
4
|
+
data.tar.gz: 0db8265872341ec18239a51144d2ec7fd288f71488f1b5bf2174726c17bf279d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5d927d414770af9512912b5ee24eeedfafbfb1987984f0ad5806e6950c1f9efc56ed542114bb1933eb9920f4fbc9367ef9f9233c2ec6c20ed170857e204010b
|
7
|
+
data.tar.gz: 2dfa0a335795a1d5b21a35b9e68a01fcc19a2ef77efaa50a91c2460e12a7cae7e3fde92d772aa4fbc7f285bafbf5ceb98b62a7c146eb6cd140d9a748cdc02b97
|
@@ -4,16 +4,16 @@
|
|
4
4
|
# https://puppet.com/docs/puppet/7/style_guide.html#style_guide_classes-param-indentation-alignment
|
5
5
|
|
6
6
|
def a_param?(token)
|
7
|
-
if token
|
7
|
+
if token&.prev_code_token&.type == :EQUALS
|
8
8
|
false
|
9
|
-
elsif token
|
9
|
+
elsif token&.prev_code_token&.type == :FARROW
|
10
10
|
false
|
11
|
-
elsif token
|
11
|
+
elsif token&.type == :VARIABLE && !%i[DQPRE DQMID].include?(token.prev_code_token.type)
|
12
12
|
true
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def first_on_the_line?(token, type)
|
17
17
|
origin = token
|
18
18
|
while token&.prev_token
|
19
19
|
token = token.prev_token
|
@@ -24,7 +24,7 @@ def first_param_on_the_line?(token)
|
|
24
24
|
while token&.next_token
|
25
25
|
token = token.next_token
|
26
26
|
|
27
|
-
break if token.type ==
|
27
|
+
break if token.type == type
|
28
28
|
end
|
29
29
|
|
30
30
|
origin == token
|
@@ -33,9 +33,9 @@ end
|
|
33
33
|
def the_one?(token, character)
|
34
34
|
case character
|
35
35
|
when '='
|
36
|
-
true if token.type == :EQUALS
|
36
|
+
true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
|
37
37
|
when '$'
|
38
|
-
true if
|
38
|
+
true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -148,30 +148,14 @@ end
|
|
148
148
|
# This function is copied & modified from puppet-lint arrow_alignment fix
|
149
149
|
# https://github.com/puppetlabs/puppet-lint/blob/020143b705b023946739eb44e7c7d99fcd087527/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb#L94
|
150
150
|
def fix_for(problem)
|
151
|
-
if problem[:newline]
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
problem[:token].prev_code_token.prev_token.value = ' ' * problem[:newline_indent]
|
160
|
-
|
161
|
-
end_param_idx = tokens.index(problem[:token].prev_code_token)
|
162
|
-
start_param_idx = tokens.index(problem[:token].prev_token_of(%i[INDENT NEWLINE]))
|
163
|
-
param_length = tokens[start_param_idx..end_param_idx].map do |r|
|
164
|
-
r.to_manifest.length
|
165
|
-
end.reduce(0) { |sum, x| sum + x } + 1
|
166
|
-
new_ws_len = problem[:arrow_column] - param_length
|
167
|
-
else
|
168
|
-
new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
|
169
|
-
problem[:token].prev_token.to_manifest.length
|
170
|
-
else
|
171
|
-
0
|
172
|
-
end
|
173
|
-
new_ws_len += (problem[:arrow_column] - problem[:token].column)
|
174
|
-
end
|
151
|
+
raise PuppetLint::NoFix if problem[:newline]
|
152
|
+
|
153
|
+
new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
|
154
|
+
problem[:token].prev_token.to_manifest.length
|
155
|
+
else
|
156
|
+
0
|
157
|
+
end
|
158
|
+
new_ws_len += (problem[:arrow_column] - problem[:token].column)
|
175
159
|
|
176
160
|
if new_ws_len.negative?
|
177
161
|
raise PuppetLint::NoFix if problem[:token].prev_token.type != :INDENT
|
@@ -241,13 +241,12 @@ describe 'class_equals_alignment' do
|
|
241
241
|
END
|
242
242
|
end
|
243
243
|
|
244
|
-
it 'should detect
|
245
|
-
expect(problems).to have(
|
244
|
+
it 'should detect 1 problem' do
|
245
|
+
expect(problems).to have(1).problems
|
246
246
|
end
|
247
247
|
|
248
|
-
it 'should create
|
248
|
+
it 'should create 1 warning' do
|
249
249
|
expect(problems).to contain_warning(format(msg, 18, 16)).on_line(2).in_column(16)
|
250
|
-
expect(problems).to contain_warning(format(msg, 18, 29)).on_line(2).in_column(29)
|
251
250
|
end
|
252
251
|
end
|
253
252
|
end
|
@@ -424,23 +423,21 @@ describe 'class_equals_alignment' do
|
|
424
423
|
let(:fixed) do
|
425
424
|
<<-END
|
426
425
|
class test (
|
427
|
-
$a = 'foo',
|
428
|
-
$bb = 'bar',
|
426
|
+
$a = 'foo', $bb = 'bar',
|
429
427
|
$ccc = 'baz',
|
430
428
|
) {}
|
431
429
|
END
|
432
430
|
end
|
433
431
|
|
434
|
-
it 'should detect
|
435
|
-
expect(problems).to have(
|
432
|
+
it 'should detect 1 problem' do
|
433
|
+
expect(problems).to have(1).problems
|
436
434
|
end
|
437
435
|
|
438
|
-
it 'should fix
|
436
|
+
it 'should fix 1 problem' do
|
439
437
|
expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
|
440
|
-
expect(problems).to contain_fixed(format(msg, 18, 29)).on_line(2).in_column(29)
|
441
438
|
end
|
442
439
|
|
443
|
-
it 'should move the extra param onto its own line and realign' do
|
440
|
+
it 'should not move the extra param onto its own line and realign' do
|
444
441
|
expect(manifest).to eq(fixed)
|
445
442
|
end
|
446
443
|
end
|
@@ -458,24 +455,21 @@ describe 'class_equals_alignment' do
|
|
458
455
|
let(:fixed) do
|
459
456
|
<<-END
|
460
457
|
class test (
|
461
|
-
$a
|
462
|
-
$
|
463
|
-
$ccc = 'baz',
|
458
|
+
$a = 'foo', $bbccc = 'bar',
|
459
|
+
$ccc = 'baz',
|
464
460
|
) {}
|
465
461
|
END
|
466
462
|
end
|
467
463
|
|
468
|
-
it 'should detect
|
469
|
-
expect(problems).to have(
|
464
|
+
it 'should detect 1 problem' do
|
465
|
+
expect(problems).to have(1).problems
|
470
466
|
end
|
471
467
|
|
472
|
-
it 'should fix
|
473
|
-
expect(problems).to contain_fixed(format(msg,
|
474
|
-
expect(problems).to contain_fixed(format(msg, 20, 32)).on_line(2).in_column(32)
|
475
|
-
expect(problems).to contain_fixed(format(msg, 20, 18)).on_line(3).in_column(18)
|
468
|
+
it 'should fix 1 problem' do
|
469
|
+
expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
|
476
470
|
end
|
477
471
|
|
478
|
-
it 'should move the extra param onto its own line and realign' do
|
472
|
+
it 'should not move the extra param onto its own line and realign' do
|
479
473
|
expect(manifest).to eq(fixed)
|
480
474
|
end
|
481
475
|
end
|