puppet-lint-manifest_whitespace-check 0.0.1 → 0.1.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.
@@ -0,0 +1,470 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'manifest_whitespace_opening_bracket_before' do
6
+ let(:opening_bracket_msg) { 'there should be a single space before an opening bracket' }
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 0 problems' do
45
+ expect(problems).to have(0).problem
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'with two spaces' do
51
+ let(:code) do
52
+ <<~EOF
53
+ # example
54
+ #
55
+ # Main class, includes all other classes.
56
+ #
57
+
58
+ class example (
59
+ String $content,
60
+ ) {
61
+ $value = [{ 'key' => 'value' }]
62
+ $value2 = [
63
+ {
64
+ 'key' => 'value1',
65
+ },
66
+ {
67
+ 'key' => 'value2',
68
+ },
69
+ ]
70
+ $value3 = myfunc($value1)
71
+
72
+ if somecondition {
73
+ class { 'example2':
74
+ param1 => 'value1',
75
+ require => File['somefile'],
76
+ }
77
+ }
78
+ }
79
+ EOF
80
+ end
81
+
82
+ context 'with fix disabled' do
83
+ it 'should detect a 2 problems' do
84
+ expect(problems).to have(2).problems
85
+ end
86
+
87
+ it 'should create a error' do
88
+ expect(problems).to contain_error(opening_bracket_msg).on_line(9).in_column(13)
89
+ end
90
+ end
91
+
92
+ context 'with fix enabled' do
93
+ before do
94
+ PuppetLint.configuration.fix = true
95
+ end
96
+
97
+ after do
98
+ PuppetLint.configuration.fix = false
99
+ end
100
+
101
+ it 'should detect a 2 problems' do
102
+ expect(problems).to have(2).problems
103
+ end
104
+
105
+ it 'should create a error' do
106
+ expect(problems).to contain_fixed(opening_bracket_msg)
107
+ end
108
+
109
+ it 'should remove a space' do
110
+ expect(manifest).to eq(
111
+ <<~EOF,
112
+ # example
113
+ #
114
+ # Main class, includes all other classes.
115
+ #
116
+
117
+ class example (
118
+ String $content,
119
+ ) {
120
+ $value = [{ 'key' => 'value' }]
121
+ $value2 = [
122
+ {
123
+ 'key' => 'value1',
124
+ },
125
+ {
126
+ 'key' => 'value2',
127
+ },
128
+ ]
129
+ $value3 = myfunc($value1)
130
+
131
+ if somecondition {
132
+ class { 'example2':
133
+ param1 => 'value1',
134
+ require => File['somefile'],
135
+ }
136
+ }
137
+ }
138
+ EOF
139
+ )
140
+ end
141
+ end
142
+ end
143
+
144
+ context 'with newline' do
145
+ let(:code) do
146
+ <<~EOF
147
+ # example
148
+ #
149
+ # Main class, includes all other classes.
150
+ #
151
+
152
+ class example (
153
+ String $content,
154
+ )
155
+ {
156
+ $value = [{ 'key' => 'value' }]
157
+ $value2 = [
158
+ {
159
+ 'key' => 'value1',
160
+ },
161
+ {
162
+ 'key' => 'value2',
163
+ },
164
+ ]
165
+ $value3 = myfunc($value1)
166
+
167
+ if somecondition
168
+ {
169
+ class
170
+ { 'example2':
171
+ param1 => 'value1',
172
+ require => File['somefile'],
173
+ }
174
+ }
175
+ }
176
+ EOF
177
+ end
178
+
179
+ context 'with fix disabled' do
180
+ it 'should detect a no problems' do
181
+ expect(problems).to have(0).problem
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'with comment' do
187
+ let(:code) do
188
+ <<~EOF
189
+ # example
190
+ #
191
+ # Main class, includes all other classes.
192
+ #
193
+
194
+ class example (
195
+ String $content,
196
+ ) # some generic comment
197
+ {
198
+ $value = [{ 'key' => 'value' }]
199
+ $value2 = [
200
+ {
201
+ 'key' => 'value1',
202
+ },
203
+ {
204
+ 'key' => 'value2',
205
+ },
206
+ ]
207
+ $value3 = myfunc($value1)
208
+
209
+ if somecondition # some generic comment
210
+ {
211
+ class { 'example2':
212
+ param1 => 'value1',
213
+ require => File['somefile'],
214
+ }
215
+ }
216
+ }
217
+ EOF
218
+ end
219
+
220
+ context 'with fix disabled' do
221
+ it 'should detect a no problems' do
222
+ expect(problems).to have(0).problem
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ describe 'manifest_whitespace_opening_bracket_after' do
229
+ let(:opening_bracket_msg) { 'there should be no whitespace or a single newline after an opening bracket' }
230
+
231
+ context 'with a single space' do
232
+ let(:code) do
233
+ <<~EOF
234
+ # example
235
+ #
236
+ # Main class, includes all other classes.
237
+ #
238
+
239
+ class example (
240
+ String $content,
241
+ ) {
242
+ $value = [ { 'key' => 'value' }]
243
+ $value2 = [
244
+ {
245
+ 'key' => 'value1',
246
+ },
247
+ {
248
+ 'key' => 'value2',
249
+ },
250
+ ]
251
+ $value3 = myfunc($value1)
252
+ $value4 = [ 'somekey']
253
+ $value5 = [ ]
254
+ $value6 = {}
255
+
256
+ if somecondition {
257
+ class { 'example2':
258
+ param1 => 'value1',
259
+ require => File[ 'somefile'],
260
+ }
261
+ }
262
+ }
263
+ EOF
264
+ end
265
+
266
+ context 'with fix disabled' do
267
+ it 'should detect 4 problems' do
268
+ expect(problems).to have(4).problem
269
+ end
270
+
271
+ it 'should create a error' do
272
+ expect(problems).to contain_error(opening_bracket_msg).on_line(9).in_column(13)
273
+ end
274
+ end
275
+
276
+ context 'with fix enabled' do
277
+ before do
278
+ PuppetLint.configuration.fix = true
279
+ end
280
+
281
+ after do
282
+ PuppetLint.configuration.fix = false
283
+ end
284
+
285
+ it 'should create a error' do
286
+ expect(problems).to contain_fixed(opening_bracket_msg)
287
+ end
288
+
289
+ it 'should add spaces' do
290
+ expect(manifest).to eq(
291
+ <<~EOF,
292
+ # example
293
+ #
294
+ # Main class, includes all other classes.
295
+ #
296
+
297
+ class example (
298
+ String $content,
299
+ ) {
300
+ $value = [{ 'key' => 'value' }]
301
+ $value2 = [
302
+ {
303
+ 'key' => 'value1',
304
+ },
305
+ {
306
+ 'key' => 'value2',
307
+ },
308
+ ]
309
+ $value3 = myfunc($value1)
310
+ $value4 = ['somekey']
311
+ $value5 = []
312
+ $value6 = {}
313
+
314
+ if somecondition {
315
+ class { 'example2':
316
+ param1 => 'value1',
317
+ require => File['somefile'],
318
+ }
319
+ }
320
+ }
321
+ EOF
322
+ )
323
+ end
324
+ end
325
+ end
326
+
327
+ context 'with no spaces' do
328
+ let(:code) do
329
+ <<~EOF
330
+ # example
331
+ #
332
+ # Main class, includes all other classes.
333
+ #
334
+
335
+ class example (
336
+ String $content,
337
+ ) {
338
+ $value = [{'key' => 'value' }]
339
+ $value2 = [
340
+ {
341
+ 'key' => 'value1',
342
+ },
343
+ {
344
+ 'key' => 'value2',
345
+ },
346
+ ]
347
+ $value3 = myfunc($value1)
348
+
349
+ if somecondition {
350
+ class {'example2':
351
+ param1 => 'value1',
352
+ require => File['somefile'],
353
+ }
354
+ }
355
+ }
356
+ EOF
357
+ end
358
+
359
+ context 'with fix disabled' do
360
+ it 'should detect 0 problems' do
361
+ expect(problems).to have(0).problem
362
+ end
363
+ end
364
+ end
365
+
366
+ context 'with two newlines' do
367
+ let(:code) do
368
+ <<~EOF
369
+ # example
370
+ #
371
+ # Main class, includes all other classes.
372
+ #
373
+
374
+ class example (
375
+ String $content,
376
+ ) {
377
+
378
+ $value = [{ 'key' => 'value' }]
379
+ $value2 = [
380
+
381
+ {
382
+
383
+ 'key' => 'value1',
384
+ },
385
+ {
386
+ 'key' => 'value2',
387
+ },
388
+ ]
389
+ $value3 = myfunc($value1)
390
+
391
+ if somecondition {
392
+
393
+ class {
394
+
395
+ 'example2':
396
+ param1 => 'value1',
397
+ require => File['somefile'],
398
+ }
399
+ }
400
+ }
401
+ EOF
402
+ end
403
+
404
+ context 'with fix disabled' do
405
+ it 'should detect 1 problems' do
406
+ expect(problems).to have(1).problem
407
+ end
408
+
409
+ it 'should create a error' do
410
+ expect(problems).to contain_error(opening_bracket_msg).on_line(12).in_column(1)
411
+ end
412
+ end
413
+
414
+ context 'with fix enabled' do
415
+ before do
416
+ PuppetLint.configuration.fix = true
417
+ end
418
+
419
+ after do
420
+ PuppetLint.configuration.fix = false
421
+ end
422
+
423
+ it 'should detect 1 problems' do
424
+ expect(problems).to have(1).problem
425
+ end
426
+
427
+ it 'should create a error' do
428
+ expect(problems).to contain_fixed(opening_bracket_msg)
429
+ end
430
+
431
+ it 'should add spaces' do
432
+ expect(manifest).to eq(
433
+ <<~EOF,
434
+ # example
435
+ #
436
+ # Main class, includes all other classes.
437
+ #
438
+
439
+ class example (
440
+ String $content,
441
+ ) {
442
+
443
+ $value = [{ 'key' => 'value' }]
444
+ $value2 = [
445
+ {
446
+
447
+ 'key' => 'value1',
448
+ },
449
+ {
450
+ 'key' => 'value2',
451
+ },
452
+ ]
453
+ $value3 = myfunc($value1)
454
+
455
+ if somecondition {
456
+
457
+ class {
458
+
459
+ 'example2':
460
+ param1 => 'value1',
461
+ require => File['somefile'],
462
+ }
463
+ }
464
+ }
465
+ EOF
466
+ )
467
+ end
468
+ end
469
+ end
470
+ end