puppet-lint-manifest_whitespace-check 0.0.1
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +153 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_arrow_spaces.rb +30 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb +73 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_class_opening_curly_brace.rb +40 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_newline_beginning_of_file.rb +21 -0
- data/lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb +46 -0
- data/lib/puppet-lint/plugins/tools.rb +9 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_arrow_spaces_spec.rb +249 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_class_header_spec.rb +559 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_double_newline_end_of_file_spec.rb +136 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_missing_newline_end_of_file_spec.rb +51 -0
- data/spec/puppet-lint/plugins/manifest_whitespace_newline_begin_of_file_spec.rb +136 -0
- data/spec/spec_helper.rb +6 -0
- metadata +168 -0
@@ -0,0 +1,559 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'manifest_whitespace_class_name_single_space_before' do
|
6
|
+
let(:single_space_msg) { 'there should be a single space between the class or defined resource statement and the name' }
|
7
|
+
|
8
|
+
context 'with two spaces' do
|
9
|
+
let(:code) do
|
10
|
+
<<~EOF
|
11
|
+
# example
|
12
|
+
#
|
13
|
+
# Main class, includes all other classes.
|
14
|
+
#
|
15
|
+
|
16
|
+
class example {
|
17
|
+
class { 'example2':
|
18
|
+
param1 => 'value1',
|
19
|
+
}
|
20
|
+
}
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with fix disabled' do
|
25
|
+
it 'should detect a single problem' do
|
26
|
+
expect(problems).to have(1).problem
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should create a error' do
|
30
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(6)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with fix enabled' do
|
35
|
+
before do
|
36
|
+
PuppetLint.configuration.fix = true
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
PuppetLint.configuration.fix = false
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should detect a single problem' do
|
44
|
+
expect(problems).to have(1).problem
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should fix the manifest' do
|
48
|
+
expect(problems).to contain_fixed(single_space_msg)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should fix the space' do
|
52
|
+
expect(manifest).to eq(
|
53
|
+
<<~EOF,
|
54
|
+
# example
|
55
|
+
#
|
56
|
+
# Main class, includes all other classes.
|
57
|
+
#
|
58
|
+
|
59
|
+
class example {
|
60
|
+
class { 'example2':
|
61
|
+
param1 => 'value1',
|
62
|
+
}
|
63
|
+
}
|
64
|
+
EOF
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'manifest_whitespace_class_name_single_space_after' do
|
72
|
+
let(:single_space_msg) { 'there should be a single space between the class or resource name and the first bracket' }
|
73
|
+
|
74
|
+
context 'with no spaces' do
|
75
|
+
let(:code) do
|
76
|
+
<<~EOF
|
77
|
+
# example
|
78
|
+
#
|
79
|
+
# Main class, includes all other classes.
|
80
|
+
#
|
81
|
+
|
82
|
+
class example{
|
83
|
+
class { 'example2':
|
84
|
+
param1 => 'value1',
|
85
|
+
}
|
86
|
+
}
|
87
|
+
EOF
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with fix disabled' do
|
91
|
+
it 'should detect a single problem' do
|
92
|
+
expect(problems).to have(1).problem
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should create a error' do
|
96
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with fix enabled' do
|
101
|
+
before do
|
102
|
+
PuppetLint.configuration.fix = true
|
103
|
+
end
|
104
|
+
|
105
|
+
after do
|
106
|
+
PuppetLint.configuration.fix = false
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should detect a single problem' do
|
110
|
+
expect(problems).to have(1).problem
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should fix the manifest' do
|
114
|
+
expect(problems).to contain_fixed(single_space_msg)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should fix the newline' do
|
118
|
+
expect(manifest).to eq(
|
119
|
+
<<~EOF,
|
120
|
+
# example
|
121
|
+
#
|
122
|
+
# Main class, includes all other classes.
|
123
|
+
#
|
124
|
+
|
125
|
+
class example {
|
126
|
+
class { 'example2':
|
127
|
+
param1 => 'value1',
|
128
|
+
}
|
129
|
+
}
|
130
|
+
EOF
|
131
|
+
)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'with two spaces' do
|
137
|
+
let(:code) do
|
138
|
+
<<~EOF
|
139
|
+
# example
|
140
|
+
#
|
141
|
+
# Main class, includes all other classes.
|
142
|
+
#
|
143
|
+
|
144
|
+
class example {
|
145
|
+
class { 'example2':
|
146
|
+
param1 => 'value1',
|
147
|
+
}
|
148
|
+
}
|
149
|
+
EOF
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'with fix disabled' do
|
153
|
+
it 'should detect a single problem' do
|
154
|
+
expect(problems).to have(1).problem
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should create a error' do
|
158
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'with fix enabled' do
|
163
|
+
before do
|
164
|
+
PuppetLint.configuration.fix = true
|
165
|
+
end
|
166
|
+
|
167
|
+
after do
|
168
|
+
PuppetLint.configuration.fix = false
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should detect a single problem' do
|
172
|
+
expect(problems).to have(1).problem
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should fix the manifest' do
|
176
|
+
expect(problems).to contain_fixed(single_space_msg)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should fix the space' do
|
180
|
+
expect(manifest).to eq(
|
181
|
+
<<~EOF,
|
182
|
+
# example
|
183
|
+
#
|
184
|
+
# Main class, includes all other classes.
|
185
|
+
#
|
186
|
+
|
187
|
+
class example {
|
188
|
+
class { 'example2':
|
189
|
+
param1 => 'value1',
|
190
|
+
}
|
191
|
+
}
|
192
|
+
EOF
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'with newline' do
|
199
|
+
let(:code) do
|
200
|
+
<<~EOF
|
201
|
+
# example
|
202
|
+
#
|
203
|
+
# Main class, includes all other classes.
|
204
|
+
#
|
205
|
+
|
206
|
+
class example
|
207
|
+
|
208
|
+
|
209
|
+
{
|
210
|
+
class { 'example2':
|
211
|
+
param1 => 'value1',
|
212
|
+
}
|
213
|
+
}
|
214
|
+
EOF
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'with fix disabled' do
|
218
|
+
it 'should detect a single problem' do
|
219
|
+
expect(problems).to have(1).problem
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should create a error' do
|
223
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'with fix enabled' do
|
228
|
+
before do
|
229
|
+
PuppetLint.configuration.fix = true
|
230
|
+
end
|
231
|
+
|
232
|
+
after do
|
233
|
+
PuppetLint.configuration.fix = false
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should detect a single problem' do
|
237
|
+
expect(problems).to have(1).problem
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should fix the manifest' do
|
241
|
+
expect(problems).to contain_fixed(single_space_msg)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should fix the newline' do
|
245
|
+
expect(manifest).to eq(
|
246
|
+
<<~EOF,
|
247
|
+
# example
|
248
|
+
#
|
249
|
+
# Main class, includes all other classes.
|
250
|
+
#
|
251
|
+
|
252
|
+
class example {
|
253
|
+
class { 'example2':
|
254
|
+
param1 => 'value1',
|
255
|
+
}
|
256
|
+
}
|
257
|
+
EOF
|
258
|
+
)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'with comment' do
|
264
|
+
let(:code) do
|
265
|
+
<<~EOF
|
266
|
+
# example
|
267
|
+
#
|
268
|
+
# Main class, includes all other classes.
|
269
|
+
#
|
270
|
+
|
271
|
+
class example # the class
|
272
|
+
{
|
273
|
+
class { 'example2':
|
274
|
+
param1 => 'value1',
|
275
|
+
}
|
276
|
+
}
|
277
|
+
EOF
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'with fix disabled' do
|
281
|
+
it 'should detect a single problem' do
|
282
|
+
expect(problems).to have(1).problem
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should create a error' do
|
286
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'with fix enabled' do
|
291
|
+
before do
|
292
|
+
PuppetLint.configuration.fix = true
|
293
|
+
end
|
294
|
+
|
295
|
+
after do
|
296
|
+
PuppetLint.configuration.fix = false
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'should detect a single problem' do
|
300
|
+
expect(problems).to have(1).problem
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should not fix the manifest' do
|
304
|
+
expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe 'manifest_whitespace_class_opening_curly_brace' do
|
311
|
+
let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly bracket of a class body' }
|
312
|
+
|
313
|
+
context 'with no spaces' do
|
314
|
+
let(:code) do
|
315
|
+
<<~EOF
|
316
|
+
# example
|
317
|
+
#
|
318
|
+
# Main class, includes all other classes.
|
319
|
+
#
|
320
|
+
|
321
|
+
class example (
|
322
|
+
String $content,
|
323
|
+
){
|
324
|
+
class { 'example2':
|
325
|
+
param1 => 'value1',
|
326
|
+
}
|
327
|
+
}
|
328
|
+
EOF
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'with fix disabled' do
|
332
|
+
it 'should detect a single problem' do
|
333
|
+
expect(problems).to have(1).problem
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'should create a error' do
|
337
|
+
expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(8).in_column(2)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'with fix enabled' do
|
342
|
+
before do
|
343
|
+
PuppetLint.configuration.fix = true
|
344
|
+
end
|
345
|
+
|
346
|
+
after do
|
347
|
+
PuppetLint.configuration.fix = false
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'should detect a single problem' do
|
351
|
+
expect(problems).to have(1).problem
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should create a error' do
|
355
|
+
expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'should add a space' do
|
359
|
+
expect(manifest).to eq(
|
360
|
+
<<~EOF,
|
361
|
+
# example
|
362
|
+
#
|
363
|
+
# Main class, includes all other classes.
|
364
|
+
#
|
365
|
+
|
366
|
+
class example (
|
367
|
+
String $content,
|
368
|
+
) {
|
369
|
+
class { 'example2':
|
370
|
+
param1 => 'value1',
|
371
|
+
}
|
372
|
+
}
|
373
|
+
EOF
|
374
|
+
)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context 'with two spaces' do
|
380
|
+
let(:code) do
|
381
|
+
<<~EOF
|
382
|
+
# example
|
383
|
+
#
|
384
|
+
# Main class, includes all other classes.
|
385
|
+
#
|
386
|
+
|
387
|
+
class example (
|
388
|
+
String $content,
|
389
|
+
) {
|
390
|
+
class { 'example2':
|
391
|
+
param1 => 'value1',
|
392
|
+
}
|
393
|
+
}
|
394
|
+
EOF
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'with fix disabled' do
|
398
|
+
it 'should detect a single problem' do
|
399
|
+
expect(problems).to have(1).problem
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should create a error' do
|
403
|
+
expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(8).in_column(4)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
context 'with fix enabled' do
|
408
|
+
before do
|
409
|
+
PuppetLint.configuration.fix = true
|
410
|
+
end
|
411
|
+
|
412
|
+
after do
|
413
|
+
PuppetLint.configuration.fix = false
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'should detect a single problem' do
|
417
|
+
expect(problems).to have(1).problem
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'should create a error' do
|
421
|
+
expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'should remove a space' do
|
425
|
+
expect(manifest).to eq(
|
426
|
+
<<~EOF,
|
427
|
+
# example
|
428
|
+
#
|
429
|
+
# Main class, includes all other classes.
|
430
|
+
#
|
431
|
+
|
432
|
+
class example (
|
433
|
+
String $content,
|
434
|
+
) {
|
435
|
+
class { 'example2':
|
436
|
+
param1 => 'value1',
|
437
|
+
}
|
438
|
+
}
|
439
|
+
EOF
|
440
|
+
)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context 'with newline' do
|
446
|
+
let(:code) do
|
447
|
+
<<~EOF
|
448
|
+
# example
|
449
|
+
#
|
450
|
+
# Main class, includes all other classes.
|
451
|
+
#
|
452
|
+
|
453
|
+
class example (
|
454
|
+
String $content,
|
455
|
+
)
|
456
|
+
{
|
457
|
+
class { 'example2':
|
458
|
+
param1 => 'value1',
|
459
|
+
}
|
460
|
+
}
|
461
|
+
EOF
|
462
|
+
end
|
463
|
+
|
464
|
+
context 'with fix disabled' do
|
465
|
+
it 'should detect a single problem' do
|
466
|
+
expect(problems).to have(1).problem
|
467
|
+
end
|
468
|
+
|
469
|
+
it 'should create a error' do
|
470
|
+
expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context 'with fix enabled' do
|
475
|
+
before do
|
476
|
+
PuppetLint.configuration.fix = true
|
477
|
+
end
|
478
|
+
|
479
|
+
after do
|
480
|
+
PuppetLint.configuration.fix = false
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'should detect a single problem' do
|
484
|
+
expect(problems).to have(1).problem
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'should create a error' do
|
488
|
+
expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'should fix the newline' do
|
492
|
+
expect(manifest).to eq(
|
493
|
+
<<~EOF,
|
494
|
+
# example
|
495
|
+
#
|
496
|
+
# Main class, includes all other classes.
|
497
|
+
#
|
498
|
+
|
499
|
+
class example (
|
500
|
+
String $content,
|
501
|
+
) {
|
502
|
+
class { 'example2':
|
503
|
+
param1 => 'value1',
|
504
|
+
}
|
505
|
+
}
|
506
|
+
EOF
|
507
|
+
)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context 'with comment' do
|
513
|
+
let(:code) do
|
514
|
+
<<~EOF
|
515
|
+
# example
|
516
|
+
#
|
517
|
+
# Main class, includes all other classes.
|
518
|
+
#
|
519
|
+
|
520
|
+
class example (
|
521
|
+
String $content,
|
522
|
+
) # the class
|
523
|
+
{
|
524
|
+
class { 'example2':
|
525
|
+
param1 => 'value1',
|
526
|
+
}
|
527
|
+
}
|
528
|
+
EOF
|
529
|
+
end
|
530
|
+
|
531
|
+
context 'with fix disabled' do
|
532
|
+
it 'should detect a single problem' do
|
533
|
+
expect(problems).to have(1).problem
|
534
|
+
end
|
535
|
+
|
536
|
+
it 'should create a error' do
|
537
|
+
expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context 'with fix enabled' do
|
542
|
+
before do
|
543
|
+
PuppetLint.configuration.fix = true
|
544
|
+
end
|
545
|
+
|
546
|
+
after do
|
547
|
+
PuppetLint.configuration.fix = false
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'should detect a single problem' do
|
551
|
+
expect(problems).to have(1).problem
|
552
|
+
end
|
553
|
+
|
554
|
+
it 'should not fix the manifest' do
|
555
|
+
expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|