puppet-lint-class_alignment-check 0.3.5 → 0.3.6
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cfe3bc16f68ebdeb6b63a01f2bdefdba07052baa618e1090b25c23ea133a1b6
|
4
|
+
data.tar.gz: b75630c6a6c37634f011ad13fe6147bf3c12753780a5f417ba074bbc1a05aedb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465e680a7fc27debc8fbd2243ed8c68deae99d405ba5e82cc42aef2716f9865b198120f756cd815149b1fc43309a784b08e4662d2a49407a70d49b048ea2adf7
|
7
|
+
data.tar.gz: 467601075b7fd04ccee1b490809ff719f3a8129141a9afe03c93f2744b412cba0a8fcc6b2c54aeedc12358586d608ca0653cd6bcfa8929ccca8423192e1f482a
|
@@ -11,18 +11,24 @@ def a_param?(token)
|
|
11
11
|
return true if token&.prev_token_of(:DEFINE)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
|
12
12
|
|
13
13
|
count = 0
|
14
|
+
saw_a_comma = false
|
14
15
|
while token&.prev_token
|
15
16
|
token = token.prev_token
|
16
|
-
|
17
|
+
|
18
|
+
saw_a_comma = true if token.type == :COMMA
|
19
|
+
|
20
|
+
return false if token.type == :EQUALS && count == 0 && saw_a_comma == false
|
17
21
|
|
18
22
|
if %i[RPAREN RBRACK RBRACE].include?(token.type)
|
19
|
-
count += 1
|
20
|
-
elsif %i[LPAREN LBRACK LBRACE].include?(token.type)
|
21
23
|
count -= 1
|
24
|
+
elsif %i[LPAREN LBRACK LBRACE].include?(token.type)
|
25
|
+
count += 1
|
22
26
|
end
|
23
27
|
|
24
|
-
|
28
|
+
break if %i[CLASS DEFINE].include?(token.type)
|
25
29
|
end
|
30
|
+
|
31
|
+
true if count == 1
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -81,6 +87,39 @@ def get_prev_code_token(token, character)
|
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
90
|
+
def get_param_start_token(token)
|
91
|
+
return nil unless a_param?(token)
|
92
|
+
|
93
|
+
case token&.prev_code_token&.type
|
94
|
+
|
95
|
+
# Integer $db_port
|
96
|
+
when :TYPE
|
97
|
+
token.prev_code_token
|
98
|
+
|
99
|
+
when :CLASSREF
|
100
|
+
token.prev_code_token
|
101
|
+
|
102
|
+
# Variant[Undef, Enum['UNSET'], Stdlib::Port] $db_port
|
103
|
+
when :RBRACK
|
104
|
+
count = 0
|
105
|
+
while token&.prev_code_token
|
106
|
+
token = token.prev_code_token
|
107
|
+
case token.type
|
108
|
+
when :RBRACK
|
109
|
+
count += 1
|
110
|
+
when :LBRACK
|
111
|
+
count -= 1
|
112
|
+
end
|
113
|
+
|
114
|
+
break if count.zero?
|
115
|
+
end
|
116
|
+
token.prev_code_token
|
117
|
+
|
118
|
+
else
|
119
|
+
token
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
84
123
|
def get_prev_param_token(token)
|
85
124
|
while token&.prev_code_token
|
86
125
|
token = token.prev_code_token
|
@@ -37,9 +37,9 @@ PuppetLint.new_check(:class_params_newline) do
|
|
37
37
|
|
38
38
|
next unless a_param?(token)
|
39
39
|
|
40
|
-
if token
|
41
|
-
next if token.line != token.prev_code_token.line
|
42
|
-
elsif token.line != get_prev_param_token(token)
|
40
|
+
if get_param_start_token(token)&.prev_code_token.type == :LPAREN
|
41
|
+
next if token.line != get_param_start_token(token).prev_code_token.line
|
42
|
+
elsif token.line != get_prev_param_token(token)&.line
|
43
43
|
next
|
44
44
|
end
|
45
45
|
|
@@ -58,29 +58,7 @@ PuppetLint.new_check(:class_params_newline) do
|
|
58
58
|
|
59
59
|
def fix(problem)
|
60
60
|
token = problem[:token]
|
61
|
-
if token.type == :VARIABLE
|
62
|
-
case token&.prev_code_token&.type
|
63
|
-
# Integer $db_port
|
64
|
-
when :TYPE
|
65
|
-
token = token.prev_code_token
|
66
|
-
|
67
|
-
# Variant[Undef, Enum['UNSET'], Stdlib::Port] $db_port
|
68
|
-
when :RBRACK
|
69
|
-
count = 0
|
70
|
-
while token&.prev_code_token
|
71
|
-
token = token.prev_code_token
|
72
|
-
case token.type
|
73
|
-
when :RBRACK
|
74
|
-
count += 1
|
75
|
-
when :LBRACK
|
76
|
-
count -= 1
|
77
|
-
end
|
78
|
-
|
79
|
-
break if count.zero?
|
80
|
-
end
|
81
|
-
token = token.prev_code_token
|
82
|
-
end
|
83
|
-
end
|
61
|
+
token = get_param_start_token(token) if token.type == :VARIABLE
|
84
62
|
|
85
63
|
last_non_whitespace_token = token.prev_token
|
86
64
|
while last_non_whitespace_token&.prev_token
|
@@ -101,7 +101,7 @@ describe 'class_params_newline' do
|
|
101
101
|
class bar ($foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a,) {}
|
102
102
|
|
103
103
|
class aaa ( $foo = 1, $bar = $a,) {}
|
104
|
-
class aaa ( $foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a,) {}
|
104
|
+
class aaa ( Integer $foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a,) {}
|
105
105
|
|
106
106
|
class bbb ( $foo = 1, $bar = $a, ) {}
|
107
107
|
class bbb ( $foo = 1, $bar = $a, $foo = 1, $bar = $a, $foo = 1, $bar = $a, ) {}
|
@@ -125,6 +125,15 @@ describe 'class_params_newline' do
|
|
125
125
|
define asdf ($prefix, $pattern, $expire, $port, $prefix, $pattern, $expire, $port) { }
|
126
126
|
|
127
127
|
define asdf ($prefix, $pattern, $expire, $port, $prefix, $pattern=$a and $b, $epe=-$foo, $port=!$foo) { }
|
128
|
+
|
129
|
+
class aaa (
|
130
|
+
$aaa = func('bbb', $ccc), $bar = $a, $foo = 1, $bar = $a,
|
131
|
+
) {}
|
132
|
+
|
133
|
+
class name (
|
134
|
+
Boolean $foo,
|
135
|
+
Optional[String[1]] $bar,
|
136
|
+
) { }
|
128
137
|
END
|
129
138
|
end
|
130
139
|
|
@@ -152,7 +161,7 @@ describe 'class_params_newline' do
|
|
152
161
|
|
153
162
|
class aaa ( $foo = 1, $bar = $a,) {}
|
154
163
|
class aaa (
|
155
|
-
$foo = 1,
|
164
|
+
Integer $foo = 1,
|
156
165
|
$bar = $a,
|
157
166
|
$foo = 1,
|
158
167
|
$bar = $a,
|
@@ -225,6 +234,18 @@ describe 'class_params_newline' do
|
|
225
234
|
$epe=-$foo,
|
226
235
|
$port=!$foo
|
227
236
|
) { }
|
237
|
+
|
238
|
+
class aaa (
|
239
|
+
$aaa = func('bbb', $ccc),
|
240
|
+
$bar = $a,
|
241
|
+
$foo = 1,
|
242
|
+
$bar = $a,
|
243
|
+
) {}
|
244
|
+
|
245
|
+
class name (
|
246
|
+
Boolean $foo,
|
247
|
+
Optional[String[1]] $bar,
|
248
|
+
) { }
|
228
249
|
END
|
229
250
|
end
|
230
251
|
|