puppet-lint-manifest_whitespace-check 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +24 -2
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_inherits_single_space.rb +0 -43
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_brace.rb +96 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_closing_bracket.rb +86 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_brace.rb +83 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_opening_bracket.rb +79 -0
- data/lib/puppet-lint/plugins/tools.rb +4 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +0 -338
- data/spec/puppet-lint/plugins/manifest_whitespace_class_inherits_spec.rb +0 -239
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_brace_spec.rb +440 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_closing_bracket_spec.rb +277 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_brace_spec.rb +788 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_opening_bracket_spec.rb +470 -0
- metadata +14 -3
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_opening_curly_brace.rb +0 -40
@@ -0,0 +1,788 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'manifest_whitespace_opening_brace_before' do
|
6
|
+
let(:opening_brace_msg) { 'there should be a single space before an opening brace' }
|
7
|
+
|
8
|
+
context 'with no spaces' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
# example
|
12
|
+
#
|
13
|
+
# Main class, includes all other classes.
|
14
|
+
#
|
15
|
+
|
16
|
+
class example (
|
17
|
+
String $content,
|
18
|
+
){
|
19
|
+
$value = [{ 'key' => 'value' }]
|
20
|
+
$value2 = [
|
21
|
+
{
|
22
|
+
'key' => 'value1',
|
23
|
+
},
|
24
|
+
{
|
25
|
+
'key' => 'value2',
|
26
|
+
},
|
27
|
+
]
|
28
|
+
$value3 = myfunc($value1)
|
29
|
+
$value4 = ['somekey']
|
30
|
+
$value5 = []
|
31
|
+
$value6 = {}
|
32
|
+
|
33
|
+
if somecondition{
|
34
|
+
class{ 'example2':
|
35
|
+
param1 => 'value1',
|
36
|
+
require => File['somefile'],
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with fix disabled' do
|
44
|
+
it 'should detect three problems' do
|
45
|
+
expect(problems).to have(3).problem
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should create a error' do
|
49
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(2)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with fix enabled' do
|
54
|
+
before do
|
55
|
+
PuppetLint.configuration.fix = true
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
PuppetLint.configuration.fix = false
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should detect three problems' do
|
63
|
+
expect(problems).to have(3).problem
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should create a error' do
|
67
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should add spaces' do
|
71
|
+
expect(manifest).to eq(
|
72
|
+
<<~EOF,
|
73
|
+
# example
|
74
|
+
#
|
75
|
+
# Main class, includes all other classes.
|
76
|
+
#
|
77
|
+
|
78
|
+
class example (
|
79
|
+
String $content,
|
80
|
+
) {
|
81
|
+
$value = [{ 'key' => 'value' }]
|
82
|
+
$value2 = [
|
83
|
+
{
|
84
|
+
'key' => 'value1',
|
85
|
+
},
|
86
|
+
{
|
87
|
+
'key' => 'value2',
|
88
|
+
},
|
89
|
+
]
|
90
|
+
$value3 = myfunc($value1)
|
91
|
+
$value4 = ['somekey']
|
92
|
+
$value5 = []
|
93
|
+
$value6 = {}
|
94
|
+
|
95
|
+
if somecondition {
|
96
|
+
class { 'example2':
|
97
|
+
param1 => 'value1',
|
98
|
+
require => File['somefile'],
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
EOF
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'with two spaces' do
|
109
|
+
let(:code) do
|
110
|
+
<<~EOF
|
111
|
+
# example
|
112
|
+
#
|
113
|
+
# Main class, includes all other classes.
|
114
|
+
#
|
115
|
+
|
116
|
+
class example (
|
117
|
+
String $content,
|
118
|
+
) {
|
119
|
+
$value = [{ 'key' => 'value' }]
|
120
|
+
$value2 = [
|
121
|
+
{
|
122
|
+
'key' => 'value1',
|
123
|
+
},
|
124
|
+
{
|
125
|
+
'key' => 'value2',
|
126
|
+
},
|
127
|
+
]
|
128
|
+
$value3 = myfunc($value1)
|
129
|
+
|
130
|
+
if somecondition {
|
131
|
+
class { 'example2':
|
132
|
+
param1 => 'value1',
|
133
|
+
require => File['somefile'],
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
EOF
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with fix disabled' do
|
141
|
+
it 'should detect a single problem' do
|
142
|
+
expect(problems).to have(3).problem
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should create a error' do
|
146
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(4)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'with fix enabled' do
|
151
|
+
before do
|
152
|
+
PuppetLint.configuration.fix = true
|
153
|
+
end
|
154
|
+
|
155
|
+
after do
|
156
|
+
PuppetLint.configuration.fix = false
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should detect a single problem' do
|
160
|
+
expect(problems).to have(3).problem
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should create a error' do
|
164
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should remove a space' do
|
168
|
+
expect(manifest).to eq(
|
169
|
+
<<~EOF,
|
170
|
+
# example
|
171
|
+
#
|
172
|
+
# Main class, includes all other classes.
|
173
|
+
#
|
174
|
+
|
175
|
+
class example (
|
176
|
+
String $content,
|
177
|
+
) {
|
178
|
+
$value = [{ 'key' => 'value' }]
|
179
|
+
$value2 = [
|
180
|
+
{
|
181
|
+
'key' => 'value1',
|
182
|
+
},
|
183
|
+
{
|
184
|
+
'key' => 'value2',
|
185
|
+
},
|
186
|
+
]
|
187
|
+
$value3 = myfunc($value1)
|
188
|
+
|
189
|
+
if somecondition {
|
190
|
+
class { 'example2':
|
191
|
+
param1 => 'value1',
|
192
|
+
require => File['somefile'],
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
EOF
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context 'with newline' do
|
203
|
+
let(:code) do
|
204
|
+
<<~EOF
|
205
|
+
# example
|
206
|
+
#
|
207
|
+
# Main class, includes all other classes.
|
208
|
+
#
|
209
|
+
|
210
|
+
class example (
|
211
|
+
String $content,
|
212
|
+
)
|
213
|
+
{
|
214
|
+
$value = [{ 'key' => 'value' }]
|
215
|
+
$value2 = [
|
216
|
+
{
|
217
|
+
'key' => 'value1',
|
218
|
+
},
|
219
|
+
{
|
220
|
+
'key' => 'value2',
|
221
|
+
},
|
222
|
+
]
|
223
|
+
$value3 = myfunc($value1)
|
224
|
+
|
225
|
+
if somecondition
|
226
|
+
{
|
227
|
+
class
|
228
|
+
{ 'example2':
|
229
|
+
param1 => 'value1',
|
230
|
+
require => File['somefile'],
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
EOF
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'with fix disabled' do
|
238
|
+
it 'should detect a single problem' do
|
239
|
+
expect(problems).to have(3).problem
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should create a error' do
|
243
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'with fix enabled' do
|
248
|
+
before do
|
249
|
+
PuppetLint.configuration.fix = true
|
250
|
+
end
|
251
|
+
|
252
|
+
after do
|
253
|
+
PuppetLint.configuration.fix = false
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should detect a single problem' do
|
257
|
+
expect(problems).to have(3).problem
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should create a error' do
|
261
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should fix the newline' do
|
265
|
+
expect(manifest).to eq(
|
266
|
+
<<~EOF,
|
267
|
+
# example
|
268
|
+
#
|
269
|
+
# Main class, includes all other classes.
|
270
|
+
#
|
271
|
+
|
272
|
+
class example (
|
273
|
+
String $content,
|
274
|
+
) {
|
275
|
+
$value = [{ 'key' => 'value' }]
|
276
|
+
$value2 = [
|
277
|
+
{
|
278
|
+
'key' => 'value1',
|
279
|
+
},
|
280
|
+
{
|
281
|
+
'key' => 'value2',
|
282
|
+
},
|
283
|
+
]
|
284
|
+
$value3 = myfunc($value1)
|
285
|
+
|
286
|
+
if somecondition {
|
287
|
+
class { 'example2':
|
288
|
+
param1 => 'value1',
|
289
|
+
require => File['somefile'],
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
EOF
|
294
|
+
)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'with comment' do
|
300
|
+
let(:code) do
|
301
|
+
<<~EOF
|
302
|
+
# example
|
303
|
+
#
|
304
|
+
# Main class, includes all other classes.
|
305
|
+
#
|
306
|
+
|
307
|
+
class example (
|
308
|
+
String $content,
|
309
|
+
) # some generic comment
|
310
|
+
{
|
311
|
+
$value = [{ 'key' => 'value' }]
|
312
|
+
$value2 = [
|
313
|
+
{
|
314
|
+
'key' => 'value1',
|
315
|
+
},
|
316
|
+
{
|
317
|
+
'key' => 'value2',
|
318
|
+
},
|
319
|
+
]
|
320
|
+
$value3 = myfunc($value1)
|
321
|
+
|
322
|
+
if somecondition # some generic comment
|
323
|
+
{
|
324
|
+
class { 'example2':
|
325
|
+
param1 => 'value1',
|
326
|
+
require => File['somefile'],
|
327
|
+
}
|
328
|
+
}
|
329
|
+
}
|
330
|
+
EOF
|
331
|
+
end
|
332
|
+
|
333
|
+
context 'with fix disabled' do
|
334
|
+
it 'should detect a single problem' do
|
335
|
+
expect(problems).to have(2).problem
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'should create a error' do
|
339
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context 'with fix enabled' do
|
344
|
+
before do
|
345
|
+
PuppetLint.configuration.fix = true
|
346
|
+
end
|
347
|
+
|
348
|
+
after do
|
349
|
+
PuppetLint.configuration.fix = false
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should detect a single problem' do
|
353
|
+
expect(problems).to have(2).problem
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should not fix the manifest' do
|
357
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context 'with good inherits' do
|
363
|
+
let(:code) do
|
364
|
+
<<~EOF
|
365
|
+
# example
|
366
|
+
#
|
367
|
+
# Main class, includes all other classes.
|
368
|
+
#
|
369
|
+
|
370
|
+
class example (
|
371
|
+
String $content,
|
372
|
+
) inherits otherclass {
|
373
|
+
$value = [{ 'key' => 'value' }]
|
374
|
+
$value2 = [
|
375
|
+
{
|
376
|
+
'key' => 'value1',
|
377
|
+
},
|
378
|
+
{
|
379
|
+
'key' => 'value2',
|
380
|
+
},
|
381
|
+
]
|
382
|
+
$value3 = myfunc($value1)
|
383
|
+
|
384
|
+
if somecondition {
|
385
|
+
class { 'example2':
|
386
|
+
param1 => 'value1',
|
387
|
+
require => File['somefile'],
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}
|
391
|
+
EOF
|
392
|
+
end
|
393
|
+
|
394
|
+
context 'with fix disabled' do
|
395
|
+
it 'should detect no problem' do
|
396
|
+
expect(problems).to have(0).problems
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
context 'with bad inherits' do
|
402
|
+
let(:code) do
|
403
|
+
<<~EOF
|
404
|
+
# example
|
405
|
+
#
|
406
|
+
# Main class, includes all other classes.
|
407
|
+
#
|
408
|
+
|
409
|
+
class example (
|
410
|
+
String $content,
|
411
|
+
) inherits otherclass{
|
412
|
+
$value = [{ 'key' => 'value' }]
|
413
|
+
$value2 = [
|
414
|
+
{
|
415
|
+
'key' => 'value1',
|
416
|
+
},
|
417
|
+
{
|
418
|
+
'key' => 'value2',
|
419
|
+
},
|
420
|
+
]
|
421
|
+
$value3 = myfunc($value1)
|
422
|
+
|
423
|
+
if somecondition {
|
424
|
+
class { 'example2':
|
425
|
+
param1 => 'value1',
|
426
|
+
require => File['somefile'],
|
427
|
+
}
|
428
|
+
}
|
429
|
+
}
|
430
|
+
EOF
|
431
|
+
end
|
432
|
+
|
433
|
+
context 'with fix disabled' do
|
434
|
+
it 'should detect a single problem' do
|
435
|
+
expect(problems).to have(1).problem
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'should create a error' do
|
439
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(22)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
context 'with fix enabled' do
|
444
|
+
before do
|
445
|
+
PuppetLint.configuration.fix = true
|
446
|
+
end
|
447
|
+
|
448
|
+
after do
|
449
|
+
PuppetLint.configuration.fix = false
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'should detect a missing space' do
|
453
|
+
expect(problems).to have(1).problem
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'should add the space' do
|
457
|
+
expect(manifest).to eq(
|
458
|
+
<<~EOF,
|
459
|
+
# example
|
460
|
+
#
|
461
|
+
# Main class, includes all other classes.
|
462
|
+
#
|
463
|
+
|
464
|
+
class example (
|
465
|
+
String $content,
|
466
|
+
) inherits otherclass {
|
467
|
+
$value = [{ 'key' => 'value' }]
|
468
|
+
$value2 = [
|
469
|
+
{
|
470
|
+
'key' => 'value1',
|
471
|
+
},
|
472
|
+
{
|
473
|
+
'key' => 'value2',
|
474
|
+
},
|
475
|
+
]
|
476
|
+
$value3 = myfunc($value1)
|
477
|
+
|
478
|
+
if somecondition {
|
479
|
+
class { 'example2':
|
480
|
+
param1 => 'value1',
|
481
|
+
require => File['somefile'],
|
482
|
+
}
|
483
|
+
}
|
484
|
+
}
|
485
|
+
EOF
|
486
|
+
)
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
describe 'manifest_whitespace_opening_brace_after' do
|
493
|
+
let(:opening_brace_msg) { 'there should be a single space or single newline after an opening brace' }
|
494
|
+
|
495
|
+
context 'with two spaces' do
|
496
|
+
let(:code) do
|
497
|
+
<<~EOF
|
498
|
+
# example
|
499
|
+
#
|
500
|
+
# Main class, includes all other classes.
|
501
|
+
#
|
502
|
+
|
503
|
+
class example (
|
504
|
+
String $content,
|
505
|
+
) {
|
506
|
+
$value = [{ 'key' => 'value' }]
|
507
|
+
$value2 = [
|
508
|
+
{
|
509
|
+
'key' => 'value1',
|
510
|
+
},
|
511
|
+
{
|
512
|
+
'key' => 'value2',
|
513
|
+
},
|
514
|
+
]
|
515
|
+
$value3 = myfunc($value1)
|
516
|
+
$value4 = ['somekey']
|
517
|
+
$value5 = []
|
518
|
+
$value6 = {}
|
519
|
+
|
520
|
+
if somecondition {
|
521
|
+
class { 'example2':
|
522
|
+
param1 => 'value1',
|
523
|
+
require => File['somefile'],
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}
|
527
|
+
EOF
|
528
|
+
end
|
529
|
+
|
530
|
+
context 'with fix disabled' do
|
531
|
+
it 'should detect 2 problems' do
|
532
|
+
expect(problems).to have(2).problem
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'should create a error' do
|
536
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
context 'with fix enabled' do
|
541
|
+
before do
|
542
|
+
PuppetLint.configuration.fix = true
|
543
|
+
end
|
544
|
+
|
545
|
+
after do
|
546
|
+
PuppetLint.configuration.fix = false
|
547
|
+
end
|
548
|
+
|
549
|
+
it 'should detect 2 problems' do
|
550
|
+
expect(problems).to have(2).problem
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'should create a error' do
|
554
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
555
|
+
end
|
556
|
+
|
557
|
+
it 'should add spaces' do
|
558
|
+
expect(manifest).to eq(
|
559
|
+
<<~EOF,
|
560
|
+
# example
|
561
|
+
#
|
562
|
+
# Main class, includes all other classes.
|
563
|
+
#
|
564
|
+
|
565
|
+
class example (
|
566
|
+
String $content,
|
567
|
+
) {
|
568
|
+
$value = [{ 'key' => 'value' }]
|
569
|
+
$value2 = [
|
570
|
+
{
|
571
|
+
'key' => 'value1',
|
572
|
+
},
|
573
|
+
{
|
574
|
+
'key' => 'value2',
|
575
|
+
},
|
576
|
+
]
|
577
|
+
$value3 = myfunc($value1)
|
578
|
+
$value4 = ['somekey']
|
579
|
+
$value5 = []
|
580
|
+
$value6 = {}
|
581
|
+
|
582
|
+
if somecondition {
|
583
|
+
class { 'example2':
|
584
|
+
param1 => 'value1',
|
585
|
+
require => File['somefile'],
|
586
|
+
}
|
587
|
+
}
|
588
|
+
}
|
589
|
+
EOF
|
590
|
+
)
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
context 'with no spaces' do
|
596
|
+
let(:code) do
|
597
|
+
<<~EOF
|
598
|
+
# example
|
599
|
+
#
|
600
|
+
# Main class, includes all other classes.
|
601
|
+
#
|
602
|
+
|
603
|
+
class example (
|
604
|
+
String $content,
|
605
|
+
) {
|
606
|
+
$value = [{'key' => 'value' }]
|
607
|
+
$value2 = [
|
608
|
+
{
|
609
|
+
'key' => 'value1',
|
610
|
+
},
|
611
|
+
{
|
612
|
+
'key' => 'value2',
|
613
|
+
},
|
614
|
+
]
|
615
|
+
$value3 = myfunc($value1)
|
616
|
+
|
617
|
+
if somecondition {
|
618
|
+
class {'example2':
|
619
|
+
param1 => 'value1',
|
620
|
+
require => File['somefile'],
|
621
|
+
}
|
622
|
+
}
|
623
|
+
}
|
624
|
+
EOF
|
625
|
+
end
|
626
|
+
|
627
|
+
context 'with fix disabled' do
|
628
|
+
it 'should detect 2 problems' do
|
629
|
+
expect(problems).to have(2).problem
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'should create a error' do
|
633
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
context 'with fix enabled' do
|
638
|
+
before do
|
639
|
+
PuppetLint.configuration.fix = true
|
640
|
+
end
|
641
|
+
|
642
|
+
after do
|
643
|
+
PuppetLint.configuration.fix = false
|
644
|
+
end
|
645
|
+
|
646
|
+
it 'should detect 2 problems' do
|
647
|
+
expect(problems).to have(2).problem
|
648
|
+
end
|
649
|
+
|
650
|
+
it 'should create a error' do
|
651
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
652
|
+
end
|
653
|
+
|
654
|
+
it 'should add spaces' do
|
655
|
+
expect(manifest).to eq(
|
656
|
+
<<~EOF,
|
657
|
+
# example
|
658
|
+
#
|
659
|
+
# Main class, includes all other classes.
|
660
|
+
#
|
661
|
+
|
662
|
+
class example (
|
663
|
+
String $content,
|
664
|
+
) {
|
665
|
+
$value = [{ 'key' => 'value' }]
|
666
|
+
$value2 = [
|
667
|
+
{
|
668
|
+
'key' => 'value1',
|
669
|
+
},
|
670
|
+
{
|
671
|
+
'key' => 'value2',
|
672
|
+
},
|
673
|
+
]
|
674
|
+
$value3 = myfunc($value1)
|
675
|
+
|
676
|
+
if somecondition {
|
677
|
+
class { 'example2':
|
678
|
+
param1 => 'value1',
|
679
|
+
require => File['somefile'],
|
680
|
+
}
|
681
|
+
}
|
682
|
+
}
|
683
|
+
EOF
|
684
|
+
)
|
685
|
+
end
|
686
|
+
end
|
687
|
+
end
|
688
|
+
|
689
|
+
context 'with two newlines' do
|
690
|
+
let(:code) do
|
691
|
+
<<~EOF
|
692
|
+
# example
|
693
|
+
#
|
694
|
+
# Main class, includes all other classes.
|
695
|
+
#
|
696
|
+
|
697
|
+
class example (
|
698
|
+
String $content,
|
699
|
+
) {
|
700
|
+
|
701
|
+
$value = [{ 'key' => 'value' }]
|
702
|
+
$value2 = [
|
703
|
+
{
|
704
|
+
|
705
|
+
'key' => 'value1',
|
706
|
+
},
|
707
|
+
{
|
708
|
+
'key' => 'value2',
|
709
|
+
},
|
710
|
+
]
|
711
|
+
$value3 = myfunc($value1)
|
712
|
+
|
713
|
+
if somecondition {
|
714
|
+
|
715
|
+
class {
|
716
|
+
|
717
|
+
'example2':
|
718
|
+
param1 => 'value1',
|
719
|
+
require => File['somefile'],
|
720
|
+
}
|
721
|
+
}
|
722
|
+
}
|
723
|
+
EOF
|
724
|
+
end
|
725
|
+
|
726
|
+
context 'with fix disabled' do
|
727
|
+
it 'should detect 4 problems' do
|
728
|
+
expect(problems).to have(4).problem
|
729
|
+
end
|
730
|
+
|
731
|
+
it 'should create a error' do
|
732
|
+
expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
context 'with fix enabled' do
|
737
|
+
before do
|
738
|
+
PuppetLint.configuration.fix = true
|
739
|
+
end
|
740
|
+
|
741
|
+
after do
|
742
|
+
PuppetLint.configuration.fix = false
|
743
|
+
end
|
744
|
+
|
745
|
+
it 'should detect 4 problems' do
|
746
|
+
expect(problems).to have(4).problem
|
747
|
+
end
|
748
|
+
|
749
|
+
it 'should create a error' do
|
750
|
+
expect(problems).to contain_fixed(opening_brace_msg)
|
751
|
+
end
|
752
|
+
|
753
|
+
it 'should add spaces' do
|
754
|
+
expect(manifest).to eq(
|
755
|
+
<<~EOF,
|
756
|
+
# example
|
757
|
+
#
|
758
|
+
# Main class, includes all other classes.
|
759
|
+
#
|
760
|
+
|
761
|
+
class example (
|
762
|
+
String $content,
|
763
|
+
) {
|
764
|
+
$value = [{ 'key' => 'value' }]
|
765
|
+
$value2 = [
|
766
|
+
{
|
767
|
+
'key' => 'value1',
|
768
|
+
},
|
769
|
+
{
|
770
|
+
'key' => 'value2',
|
771
|
+
},
|
772
|
+
]
|
773
|
+
$value3 = myfunc($value1)
|
774
|
+
|
775
|
+
if somecondition {
|
776
|
+
class {
|
777
|
+
'example2':
|
778
|
+
param1 => 'value1',
|
779
|
+
require => File['somefile'],
|
780
|
+
}
|
781
|
+
}
|
782
|
+
}
|
783
|
+
EOF
|
784
|
+
)
|
785
|
+
end
|
786
|
+
end
|
787
|
+
end
|
788
|
+
end
|