puppet-lint-class_alignment-check 0.3.2 → 0.3.5
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: 40fcbe1d19cc554f3b3a18fd44e8d252f8d4e7b39d5aea1ae14bb108b84d4ed5
|
|
4
|
+
data.tar.gz: 8909d0c354b917d2516ee7fd29078a2df9523a73b0e50d010eb6d36fb0fcff70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa23065a0ab5698aaef52a521279d871c68d594825fdf31cd1820b2e07fa4d7b427c205b2eb3004d79ad54c3a88b18c4ecc1190507ee02610bfa5aaa90e65799
|
|
7
|
+
data.tar.gz: f606316e9de223a83e1940daf2d5fca115eb6968116fbe7a5983ce43d7538dd368eb2b145becd227f6602260f58b57b5e9110c9cc2dbc6055d2789aa29b2d39c
|
|
@@ -3,71 +3,6 @@
|
|
|
3
3
|
#
|
|
4
4
|
# https://puppet.com/docs/puppet/7/style_guide.html#style_guide_classes-param-indentation-alignment
|
|
5
5
|
|
|
6
|
-
def a_param?(token)
|
|
7
|
-
if token&.prev_code_token&.type == :EQUALS
|
|
8
|
-
false
|
|
9
|
-
elsif token&.prev_code_token&.type == :FARROW
|
|
10
|
-
false
|
|
11
|
-
elsif token&.type == :VARIABLE && !%i[DQPRE DQMID].include?(token.prev_code_token.type)
|
|
12
|
-
true
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def first_on_the_line?(token, type)
|
|
17
|
-
origin = token
|
|
18
|
-
while token&.prev_token
|
|
19
|
-
token = token.prev_token
|
|
20
|
-
|
|
21
|
-
break if token.type == :NEWLINE
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
while token&.next_token
|
|
25
|
-
token = token.next_token
|
|
26
|
-
|
|
27
|
-
break if token.type == type
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
origin == token
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def the_one?(token, character)
|
|
34
|
-
case character
|
|
35
|
-
when '='
|
|
36
|
-
true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
|
|
37
|
-
when '$'
|
|
38
|
-
true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def get_the_first_param(token)
|
|
43
|
-
while token&.prev_code_token
|
|
44
|
-
token = token.prev_code_token
|
|
45
|
-
break if token.type == :CLASS
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
while token&.next_code_token
|
|
49
|
-
token = token.next_code_token
|
|
50
|
-
return token if token.type == :VARIABLE
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def get_prev_code_token(token, character)
|
|
55
|
-
case character
|
|
56
|
-
when '='
|
|
57
|
-
token.prev_code_token
|
|
58
|
-
when '$'
|
|
59
|
-
if token.prev_code_token
|
|
60
|
-
if %i[CLASSREF RBRACK].include?(token.prev_code_token.type)
|
|
61
|
-
token.prev_code_token
|
|
62
|
-
elsif token.prev_code_token.type == :LPAREN
|
|
63
|
-
token
|
|
64
|
-
elsif token.prev_code_token.type == :COMMA
|
|
65
|
-
get_the_first_param(token)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
6
|
# This function is copied & modified from puppet-lint arrow_alignment check
|
|
72
7
|
# https://github.com/puppetlabs/puppet-lint/blob/020143b705b023946739eb44e7c7d99fcd087527/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb#L8
|
|
73
8
|
def check_for(character)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
def a_param?(token)
|
|
2
|
+
if token&.prev_code_token&.type == :EQUALS
|
|
3
|
+
false
|
|
4
|
+
elsif token&.prev_code_token&.type == :FARROW
|
|
5
|
+
false
|
|
6
|
+
elsif %i[DQPRE DQMID].include?(token&.prev_code_token&.type)
|
|
7
|
+
false
|
|
8
|
+
elsif token&.type == :VARIABLE
|
|
9
|
+
# first var in the class
|
|
10
|
+
return true if token&.prev_token_of(:CLASS)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
|
|
11
|
+
return true if token&.prev_token_of(:DEFINE)&.next_token_of(:LPAREN)&.next_token_of(:VARIABLE) == token
|
|
12
|
+
|
|
13
|
+
count = 0
|
|
14
|
+
while token&.prev_token
|
|
15
|
+
token = token.prev_token
|
|
16
|
+
return false if token.type == :EQUALS
|
|
17
|
+
|
|
18
|
+
if %i[RPAREN RBRACK RBRACE].include?(token.type)
|
|
19
|
+
count += 1
|
|
20
|
+
elsif %i[LPAREN LBRACK LBRACE].include?(token.type)
|
|
21
|
+
count -= 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
return true if count.zero? && token.type == :COMMA
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def first_on_the_line?(token, type)
|
|
30
|
+
origin = token
|
|
31
|
+
while token&.prev_token
|
|
32
|
+
token = token.prev_token
|
|
33
|
+
|
|
34
|
+
break if token.type == :NEWLINE
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
while token&.next_token
|
|
38
|
+
token = token.next_token
|
|
39
|
+
|
|
40
|
+
break if token.type == type
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
origin == token
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def the_one?(token, character)
|
|
47
|
+
case character
|
|
48
|
+
when '='
|
|
49
|
+
true if token.type == :EQUALS && first_on_the_line?(token, :EQUALS)
|
|
50
|
+
when '$'
|
|
51
|
+
true if a_param?(token) && first_on_the_line?(token, :VARIABLE)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def get_the_first_param(token)
|
|
56
|
+
while token&.prev_code_token
|
|
57
|
+
token = token.prev_code_token
|
|
58
|
+
break if token.type == :CLASS
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
while token&.next_code_token
|
|
62
|
+
token = token.next_code_token
|
|
63
|
+
return token if token.type == :VARIABLE
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_prev_code_token(token, character)
|
|
68
|
+
case character
|
|
69
|
+
when '='
|
|
70
|
+
token.prev_code_token
|
|
71
|
+
when '$'
|
|
72
|
+
if token.prev_code_token
|
|
73
|
+
if %i[CLASSREF RBRACK].include?(token.prev_code_token.type)
|
|
74
|
+
token.prev_code_token
|
|
75
|
+
elsif token.prev_code_token.type == :LPAREN
|
|
76
|
+
token
|
|
77
|
+
elsif token.prev_code_token.type == :COMMA
|
|
78
|
+
get_the_first_param(token)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def get_prev_param_token(token)
|
|
85
|
+
while token&.prev_code_token
|
|
86
|
+
token = token.prev_code_token
|
|
87
|
+
return token if a_param?(token)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
def prev_param_token(token)
|
|
2
|
-
while token&.prev_code_token
|
|
3
|
-
token = token.prev_code_token
|
|
4
|
-
break if a_param?(token)
|
|
5
|
-
end
|
|
6
|
-
token
|
|
7
|
-
end
|
|
8
|
-
|
|
9
1
|
PuppetLint.new_check(:class_params_newline) do
|
|
10
2
|
def check
|
|
11
3
|
(class_indexes + defined_type_indexes).each do |item|
|
|
12
4
|
tokens = item[:param_tokens]
|
|
13
5
|
next if tokens.nil?
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
next if
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
next if tokens[first_param] == tokens[last_param]
|
|
7
|
+
# Skip if line length < 80 chars
|
|
8
|
+
first_paren = tokens[0]&.prev_token_of(:LPAREN)
|
|
9
|
+
last_paren = tokens[-1]&.next_token_of(:RPAREN)
|
|
10
|
+
next if first_paren.nil?
|
|
11
|
+
next if last_paren.nil?
|
|
12
|
+
next if first_paren.line == last_paren.line && last_paren.column < 80
|
|
22
13
|
|
|
23
14
|
tokens.each do |token|
|
|
24
15
|
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
|
|
16
|
+
rparen = token.next_token_of(:RPAREN)
|
|
30
17
|
|
|
31
18
|
last_code_token = token
|
|
32
19
|
while last_code_token&.prev_token
|
|
@@ -46,14 +33,13 @@ PuppetLint.new_check(:class_params_newline) do
|
|
|
46
33
|
newline: true,
|
|
47
34
|
newline_indent: item[:tokens][0].column - 1
|
|
48
35
|
)
|
|
49
|
-
break
|
|
50
36
|
end
|
|
51
37
|
|
|
52
38
|
next unless a_param?(token)
|
|
53
39
|
|
|
54
40
|
if token.prev_code_token.type == :LPAREN
|
|
55
41
|
next if token.line != token.prev_code_token.line
|
|
56
|
-
elsif token.line !=
|
|
42
|
+
elsif token.line != get_prev_param_token(token).line
|
|
57
43
|
next
|
|
58
44
|
end
|
|
59
45
|
|
|
@@ -72,26 +58,38 @@ PuppetLint.new_check(:class_params_newline) do
|
|
|
72
58
|
|
|
73
59
|
def fix(problem)
|
|
74
60
|
token = problem[:token]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
count = 0
|
|
80
|
-
while token&.prev_code_token
|
|
61
|
+
if token.type == :VARIABLE
|
|
62
|
+
case token&.prev_code_token&.type
|
|
63
|
+
# Integer $db_port
|
|
64
|
+
when :TYPE
|
|
81
65
|
token = token.prev_code_token
|
|
82
|
-
case token.type
|
|
83
|
-
when :RBRACK
|
|
84
|
-
count += 1
|
|
85
|
-
when :LBRACK
|
|
86
|
-
count -= 1
|
|
87
|
-
end
|
|
88
66
|
|
|
89
|
-
|
|
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
|
|
90
82
|
end
|
|
91
|
-
token = token.prev_code_token
|
|
92
83
|
end
|
|
93
84
|
|
|
94
|
-
|
|
85
|
+
last_non_whitespace_token = token.prev_token
|
|
86
|
+
while last_non_whitespace_token&.prev_token
|
|
87
|
+
break unless %i[WHITESPACE INDENT NEWLINE].include?(last_non_whitespace_token.type)
|
|
88
|
+
|
|
89
|
+
last_non_whitespace_token = last_non_whitespace_token.prev_token
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
index = tokens.index(last_non_whitespace_token) + 1
|
|
95
93
|
tokens.insert(index, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
|
|
96
94
|
|
|
97
95
|
# When there's no space at the beginning of the param
|
|
@@ -95,44 +95,136 @@ 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) { }
|
|
126
|
+
|
|
127
|
+
define asdf ($prefix, $pattern, $expire, $port, $prefix, $pattern=$a and $b, $epe=-$foo, $port=!$foo) { }
|
|
108
128
|
END
|
|
109
129
|
end
|
|
110
130
|
|
|
111
131
|
let(:fixed) do
|
|
112
132
|
<<-END
|
|
133
|
+
class foo ($foo = 1, $bar = $a) {}
|
|
113
134
|
class foo (
|
|
135
|
+
$foo = 1,
|
|
136
|
+
$bar = $a,
|
|
137
|
+
$foo = 1,
|
|
138
|
+
$bar = $a,
|
|
114
139
|
$foo = 1,
|
|
115
140
|
$bar = $a
|
|
116
141
|
) {}
|
|
117
142
|
|
|
143
|
+
class bar ($foo = 1, $bar = $a,) {}
|
|
118
144
|
class bar (
|
|
119
145
|
$foo = 1,
|
|
120
146
|
$bar = $a,
|
|
147
|
+
$foo = 1,
|
|
148
|
+
$bar = $a,
|
|
149
|
+
$foo = 1,
|
|
150
|
+
$bar = $a,
|
|
121
151
|
) {}
|
|
122
152
|
|
|
153
|
+
class aaa ( $foo = 1, $bar = $a,) {}
|
|
123
154
|
class aaa (
|
|
124
155
|
$foo = 1,
|
|
125
156
|
$bar = $a,
|
|
157
|
+
$foo = 1,
|
|
158
|
+
$bar = $a,
|
|
159
|
+
$foo = 1,
|
|
160
|
+
$bar = $a,
|
|
126
161
|
) {}
|
|
127
162
|
|
|
163
|
+
class bbb ( $foo = 1, $bar = $a, ) {}
|
|
128
164
|
class bbb (
|
|
129
165
|
$foo = 1,
|
|
130
166
|
$bar = $a,
|
|
167
|
+
$foo = 1,
|
|
168
|
+
$bar = $a,
|
|
169
|
+
$foo = 1,
|
|
170
|
+
$bar = $a,
|
|
131
171
|
) {}
|
|
132
172
|
|
|
133
173
|
class ccc ($foo = 1) {}
|
|
134
174
|
|
|
135
175
|
class ddd {}
|
|
176
|
+
|
|
177
|
+
class eee (
|
|
178
|
+
$foo = 1,
|
|
179
|
+
$workers = max($::processorcount, 1),
|
|
180
|
+
$database_path = $aaa,
|
|
181
|
+
) inherits sap_zabbix::params { }
|
|
182
|
+
{ }
|
|
183
|
+
|
|
184
|
+
class fff (
|
|
185
|
+
$foo,
|
|
186
|
+
$bar=[],
|
|
187
|
+
$foo,
|
|
188
|
+
$bar=[],
|
|
189
|
+
$foo,
|
|
190
|
+
$bar=[],
|
|
191
|
+
$listen_ips = [$::ipaddress]
|
|
192
|
+
) {}
|
|
193
|
+
|
|
194
|
+
define ggg ($foo, $bar=[]) {}
|
|
195
|
+
|
|
196
|
+
define long_ggg (
|
|
197
|
+
$foo,
|
|
198
|
+
$bar=[],
|
|
199
|
+
$foo,
|
|
200
|
+
$bar=[],
|
|
201
|
+
$foo,
|
|
202
|
+
$bar=[],
|
|
203
|
+
$foo,
|
|
204
|
+
$bar=[]
|
|
205
|
+
) {}
|
|
206
|
+
|
|
207
|
+
define asdf (
|
|
208
|
+
$prefix,
|
|
209
|
+
$pattern,
|
|
210
|
+
$expire,
|
|
211
|
+
$port,
|
|
212
|
+
$prefix,
|
|
213
|
+
$pattern,
|
|
214
|
+
$expire,
|
|
215
|
+
$port
|
|
216
|
+
) { }
|
|
217
|
+
|
|
218
|
+
define asdf (
|
|
219
|
+
$prefix,
|
|
220
|
+
$pattern,
|
|
221
|
+
$expire,
|
|
222
|
+
$port,
|
|
223
|
+
$prefix,
|
|
224
|
+
$pattern=$a and $b,
|
|
225
|
+
$epe=-$foo,
|
|
226
|
+
$port=!$foo
|
|
227
|
+
) { }
|
|
136
228
|
END
|
|
137
229
|
end
|
|
138
230
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppet-lint-class_alignment-check
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anh Pham
|
|
@@ -123,6 +123,7 @@ files:
|
|
|
123
123
|
- LICENSE
|
|
124
124
|
- README.md
|
|
125
125
|
- lib/puppet-lint/plugins/check_class_alignment.rb
|
|
126
|
+
- lib/puppet-lint/plugins/check_class_helper.rb
|
|
126
127
|
- lib/puppet-lint/plugins/check_class_params_newline.rb
|
|
127
128
|
- spec/puppet-lint/plugins/check_class_equals_alignment_spec.rb
|
|
128
129
|
- spec/puppet-lint/plugins/check_class_params_alignment_spec.rb
|