puppet-lint-nine-check 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet-lint/plugins/class_alignment/helper.rb +158 -0
- data/lib/puppet-lint/plugins/class_alignment.rb +155 -0
- data/lib/puppet-lint/plugins/class_alignment_params_newline.rb +108 -0
- data/spec/puppet-lint/plugins/class_alignment_equals_spec.rb +477 -0
- data/spec/puppet-lint/plugins/class_alignment_params_newline_spec.rb +257 -0
- data/spec/puppet-lint/plugins/class_alignment_params_spec.rb +321 -0
- data/spec/spec_helper.rb +1 -0
- metadata +10 -7
@@ -0,0 +1,477 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "class_alignment_equals" do
|
4
|
+
let(:msg) { "indentation of = is not properly aligned (expected in column %d, but found it in column %d)" }
|
5
|
+
|
6
|
+
context "with fix disabled" do
|
7
|
+
context "selectors inside a resource" do
|
8
|
+
let(:code) do
|
9
|
+
<<-END
|
10
|
+
class foo (
|
11
|
+
$ensure = $ensure,
|
12
|
+
$require = $ensure ? {
|
13
|
+
present => Class['tomcat::install'],
|
14
|
+
absent => undef;
|
15
|
+
},
|
16
|
+
$foo = bar,
|
17
|
+
) {}
|
18
|
+
END
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not detect any problems" do
|
22
|
+
expect(problems).to have(0).problems
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "selectors in the middle of a resource" do
|
27
|
+
let(:code) do
|
28
|
+
<<-END
|
29
|
+
class foo (
|
30
|
+
$ensure = $ensure ? {
|
31
|
+
present => directory,
|
32
|
+
absent => undef,
|
33
|
+
},
|
34
|
+
$owner = 'tomcat6',
|
35
|
+
) {}
|
36
|
+
END
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not detect any problems" do
|
40
|
+
expect(problems).to have(0).problems
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "selector inside a resource" do
|
45
|
+
let(:code) do
|
46
|
+
<<-END
|
47
|
+
$ensure = $ensure ? {
|
48
|
+
present => directory,
|
49
|
+
absent => undef,
|
50
|
+
},
|
51
|
+
$owner = 'foo4',
|
52
|
+
$group = 'foo4',
|
53
|
+
$mode = '0755',
|
54
|
+
END
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not detect any problems" do
|
58
|
+
expect(problems).to have(0).problems
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "selector inside a hash inside a resource" do
|
63
|
+
let(:code) do
|
64
|
+
<<-END
|
65
|
+
$server = {
|
66
|
+
ensure => ensure => $ensure ? {
|
67
|
+
present => directory,
|
68
|
+
absent => undef,
|
69
|
+
},
|
70
|
+
ip => '192.168.1.1'
|
71
|
+
},
|
72
|
+
$owner = 'foo4',
|
73
|
+
$group = 'foo4',
|
74
|
+
$mode = '0755',
|
75
|
+
END
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not detect any problems" do
|
79
|
+
expect(problems).to have(0).problems
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "nested hashes with correct indentation" do
|
84
|
+
let(:code) do
|
85
|
+
<<-END
|
86
|
+
class lvs::base (
|
87
|
+
$virtualeservers = {
|
88
|
+
'192.168.2.13' => {
|
89
|
+
vport => '11025',
|
90
|
+
service => 'smtp',
|
91
|
+
scheduler => 'wlc',
|
92
|
+
protocol => 'tcp',
|
93
|
+
checktype => 'external',
|
94
|
+
checkcommand => '/path/to/checkscript',
|
95
|
+
real_servers => {
|
96
|
+
'server01' => {
|
97
|
+
real_server => '192.168.2.14',
|
98
|
+
real_port => '25',
|
99
|
+
forwarding => 'masq',
|
100
|
+
},
|
101
|
+
'server02' => {
|
102
|
+
real_server => '192.168.2.15',
|
103
|
+
real_port => '25',
|
104
|
+
forwarding => 'masq',
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
) {}
|
110
|
+
END
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not detect any problems" do
|
114
|
+
expect(problems).to have(0).problems
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "single resource with a misaligned =" do
|
119
|
+
let(:code) do
|
120
|
+
<<-END
|
121
|
+
class foo (
|
122
|
+
$foo = 1,
|
123
|
+
$bar = 2,
|
124
|
+
$gronk = 3,
|
125
|
+
$baz = 4,
|
126
|
+
$meh = 5,
|
127
|
+
) {}
|
128
|
+
END
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should detect four problems" do
|
132
|
+
expect(problems).to have(4).problems
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should create four warnings" do
|
136
|
+
expect(problems).to contain_warning(format(msg, 20, 18)).on_line(2).in_column(18)
|
137
|
+
expect(problems).to contain_warning(format(msg, 20, 18)).on_line(3).in_column(18)
|
138
|
+
expect(problems).to contain_warning(format(msg, 20, 19)).on_line(5).in_column(19)
|
139
|
+
expect(problems).to contain_warning(format(msg, 20, 18)).on_line(6).in_column(18)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "complex resource with a misaligned =" do
|
144
|
+
let(:code) do
|
145
|
+
<<-END
|
146
|
+
class foo (
|
147
|
+
$foo = 1,
|
148
|
+
$bar = $baz ? {
|
149
|
+
gronk => 2,
|
150
|
+
meh => 3,
|
151
|
+
},
|
152
|
+
$meep = 4,
|
153
|
+
$bah= 5,
|
154
|
+
) {}
|
155
|
+
END
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should detect three problems" do
|
159
|
+
expect(problems).to have(3).problems
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should create three warnings" do
|
163
|
+
expect(problems).to contain_warning(format(msg, 19, 18)).on_line(2).in_column(18)
|
164
|
+
expect(problems).to contain_warning(format(msg, 19, 20)).on_line(3).in_column(20)
|
165
|
+
expect(problems).to contain_warning(format(msg, 19, 17)).on_line(8).in_column(17)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "resource with unaligned = in commented line" do
|
170
|
+
let(:code) do
|
171
|
+
<<-END
|
172
|
+
class foo (
|
173
|
+
$ensure = directory,
|
174
|
+
# $purge = true,
|
175
|
+
) {}
|
176
|
+
END
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should not detect any problems" do
|
180
|
+
expect(problems).to have(0).problems
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "multiline resource with a single line of params" do
|
185
|
+
let(:code) do
|
186
|
+
<<-END
|
187
|
+
class mymodule::do_thing (
|
188
|
+
$whatever = 'bar', $one = 'two',
|
189
|
+
) {}
|
190
|
+
END
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should not detect any problems" do
|
194
|
+
expect(problems).to have(0).problems
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "resource with aligned = too far out" do
|
199
|
+
let(:code) do
|
200
|
+
<<-END
|
201
|
+
class foo (
|
202
|
+
$ensure = file,
|
203
|
+
$mode = '0444',
|
204
|
+
) {}
|
205
|
+
END
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should detect 2 problems" do
|
209
|
+
expect(problems).to have(2).problems
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should create 2 warnings" do
|
213
|
+
expect(problems).to contain_warning(format(msg, 21, 22)).on_line(2).in_column(22)
|
214
|
+
expect(problems).to contain_warning(format(msg, 21, 22)).on_line(3).in_column(22)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context "resource with multiple params where one is an empty hash" do
|
219
|
+
let(:code) do
|
220
|
+
<<-END
|
221
|
+
class foo (
|
222
|
+
$a = true,
|
223
|
+
$b = {
|
224
|
+
}
|
225
|
+
) {}
|
226
|
+
END
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should not detect any problems" do
|
230
|
+
expect(problems).to have(0).problems
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "multiline resource with multiple params on a line" do
|
235
|
+
let(:code) do
|
236
|
+
<<-END
|
237
|
+
class test (
|
238
|
+
$a = 'foo', $bb = 'bar',
|
239
|
+
$ccc = 'baz',
|
240
|
+
) {}
|
241
|
+
END
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should detect 1 problem" do
|
245
|
+
expect(problems).to have(1).problems
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should create 1 warning" do
|
249
|
+
expect(problems).to contain_warning(format(msg, 18, 16)).on_line(2).in_column(16)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "with fix enabled" do
|
255
|
+
before do
|
256
|
+
PuppetLint.configuration.fix = true
|
257
|
+
end
|
258
|
+
|
259
|
+
after do
|
260
|
+
PuppetLint.configuration.fix = false
|
261
|
+
end
|
262
|
+
|
263
|
+
context "single resource with a misaligned =" do
|
264
|
+
let(:code) do
|
265
|
+
<<-END
|
266
|
+
class foo (
|
267
|
+
$foo = 1,
|
268
|
+
$bar = 2,
|
269
|
+
$gronk = 3,
|
270
|
+
$baz = 4,
|
271
|
+
$meh = 5,
|
272
|
+
) {}
|
273
|
+
END
|
274
|
+
end
|
275
|
+
|
276
|
+
let(:fixed) do
|
277
|
+
<<-END
|
278
|
+
class foo (
|
279
|
+
$foo = 1,
|
280
|
+
$bar = 2,
|
281
|
+
$gronk = 3,
|
282
|
+
$baz = 4,
|
283
|
+
$meh = 5,
|
284
|
+
) {}
|
285
|
+
END
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should detect four problems" do
|
289
|
+
expect(problems).to have(4).problems
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should fix the manifest" do
|
293
|
+
expect(problems).to contain_fixed(format(msg, 20, 18)).on_line(2).in_column(18)
|
294
|
+
expect(problems).to contain_fixed(format(msg, 20, 18)).on_line(3).in_column(18)
|
295
|
+
expect(problems).to contain_fixed(format(msg, 20, 19)).on_line(5).in_column(19)
|
296
|
+
expect(problems).to contain_fixed(format(msg, 20, 18)).on_line(6).in_column(18)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should align the class_paramss" do
|
300
|
+
expect(manifest).to eq(fixed)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "complex resource with a misaligned =" do
|
305
|
+
let(:code) do
|
306
|
+
<<-END
|
307
|
+
class foo (
|
308
|
+
$foo = 1,
|
309
|
+
$bar = $baz ? {
|
310
|
+
gronk => 2,
|
311
|
+
meh => 3,
|
312
|
+
},
|
313
|
+
$meep= 4,
|
314
|
+
$bah = 5,
|
315
|
+
) {}
|
316
|
+
END
|
317
|
+
end
|
318
|
+
|
319
|
+
let(:fixed) do
|
320
|
+
<<-END
|
321
|
+
class foo (
|
322
|
+
$foo = 1,
|
323
|
+
$bar = $baz ? {
|
324
|
+
gronk => 2,
|
325
|
+
meh => 3,
|
326
|
+
},
|
327
|
+
$meep = 4,
|
328
|
+
$bah = 5,
|
329
|
+
) {}
|
330
|
+
END
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should detect three problems" do
|
334
|
+
expect(problems).to have(3).problems
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should fix the manifest" do
|
338
|
+
expect(problems).to contain_fixed(format(msg, 19, 18)).on_line(2).in_column(18)
|
339
|
+
expect(problems).to contain_fixed(format(msg, 19, 18)).on_line(7).in_column(18)
|
340
|
+
expect(problems).to contain_fixed(format(msg, 19, 18)).on_line(8).in_column(18)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should align the class_paramss" do
|
344
|
+
expect(manifest).to eq(fixed)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context "resource with aligned = too far out" do
|
349
|
+
let(:code) do
|
350
|
+
<<-END
|
351
|
+
class foo (
|
352
|
+
$ensure = file,
|
353
|
+
$mode = '0444',
|
354
|
+
) {}
|
355
|
+
END
|
356
|
+
end
|
357
|
+
|
358
|
+
let(:fixed) do
|
359
|
+
<<-END
|
360
|
+
class foo (
|
361
|
+
$ensure = file,
|
362
|
+
$mode = '0444',
|
363
|
+
) {}
|
364
|
+
END
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should detect 2 problems" do
|
368
|
+
expect(problems).to have(2).problems
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should create 2 warnings" do
|
372
|
+
expect(problems).to contain_fixed(format(msg, 21, 22)).on_line(2).in_column(22)
|
373
|
+
expect(problems).to contain_fixed(format(msg, 21, 22)).on_line(3).in_column(22)
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should realign the class_paramss with the minimum whitespace" do
|
377
|
+
expect(manifest).to eq(fixed)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context "resource with unaligned = and no whitespace between param and =" do
|
382
|
+
let(:code) do
|
383
|
+
<<-END
|
384
|
+
class test (
|
385
|
+
$param1 = 'foo',
|
386
|
+
$param2= 'bar',
|
387
|
+
) {}
|
388
|
+
END
|
389
|
+
end
|
390
|
+
|
391
|
+
let(:fixed) do
|
392
|
+
<<-END
|
393
|
+
class test (
|
394
|
+
$param1 = 'foo',
|
395
|
+
$param2 = 'bar',
|
396
|
+
) {}
|
397
|
+
END
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should detect 1 problem" do
|
401
|
+
expect(problems).to have(1).problem
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should fix the problem" do
|
405
|
+
expect(problems).to contain_fixed(format(msg, 21, 20)).on_line(3).in_column(20)
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should add whitespace between the param and the class_params" do
|
409
|
+
expect(manifest).to eq(fixed)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context "multiline resource with multiple params on a line" do
|
414
|
+
let(:code) do
|
415
|
+
<<-END
|
416
|
+
class test (
|
417
|
+
$a = 'foo', $bb = 'bar',
|
418
|
+
$ccc = 'baz',
|
419
|
+
) {}
|
420
|
+
END
|
421
|
+
end
|
422
|
+
|
423
|
+
let(:fixed) do
|
424
|
+
<<-END
|
425
|
+
class test (
|
426
|
+
$a = 'foo', $bb = 'bar',
|
427
|
+
$ccc = 'baz',
|
428
|
+
) {}
|
429
|
+
END
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should detect 1 problem" do
|
433
|
+
expect(problems).to have(1).problems
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should fix 1 problem" do
|
437
|
+
expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
|
438
|
+
end
|
439
|
+
|
440
|
+
it "should not move the extra param onto its own line and realign" do
|
441
|
+
expect(manifest).to eq(fixed)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context "multiline resource with multiple params on a line, extra one longer" do
|
446
|
+
let(:code) do
|
447
|
+
<<-END
|
448
|
+
class test (
|
449
|
+
$a = 'foo', $bbccc = 'bar',
|
450
|
+
$ccc = 'baz',
|
451
|
+
) {}
|
452
|
+
END
|
453
|
+
end
|
454
|
+
|
455
|
+
let(:fixed) do
|
456
|
+
<<-END
|
457
|
+
class test (
|
458
|
+
$a = 'foo', $bbccc = 'bar',
|
459
|
+
$ccc = 'baz',
|
460
|
+
) {}
|
461
|
+
END
|
462
|
+
end
|
463
|
+
|
464
|
+
it "should detect 1 problem" do
|
465
|
+
expect(problems).to have(1).problems
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should fix 1 problem" do
|
469
|
+
expect(problems).to contain_fixed(format(msg, 18, 16)).on_line(2).in_column(16)
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should not move the extra param onto its own line and realign" do
|
473
|
+
expect(manifest).to eq(fixed)
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|