puppet-lint-manifest_whitespace-check 0.1.2 → 0.1.8

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.
@@ -7,3 +7,19 @@ end
7
7
  def new_single_space
8
8
  PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', 0, 0)
9
9
  end
10
+
11
+ def after_bracket_tokens
12
+ %i[RBRACE RBRACK RPAREN SEMIC COMMA COLON NEWLINE DQMID DQPOST LBRACK]
13
+ end
14
+
15
+ def prev_non_space_token(token)
16
+ while token = token.prev_token
17
+ return token unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
18
+ end
19
+ end
20
+
21
+ def next_non_space_token(token)
22
+ while token = token.next_token
23
+ return token unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
24
+ end
25
+ end
@@ -66,10 +66,34 @@ describe 'manifest_whitespace_class_name_single_space_before' do
66
66
  end
67
67
  end
68
68
  end
69
+
70
+ context 'with inherits' do
71
+ let(:code) do
72
+ 'class example inherits otherexample {'
73
+ end
74
+
75
+ it 'should detect no problems' do
76
+ expect(problems).to have(0).problem
77
+ end
78
+ end
69
79
  end
70
80
 
71
81
  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 brace' }
82
+ let(:single_space_msg) { 'there should be a single space between the class or resource name and the next item' }
83
+
84
+ context 'with inherits' do
85
+ let(:code) do
86
+ <<~EOF
87
+ class example inherits otherexample {
88
+ assert_private()
89
+ }
90
+ EOF
91
+ end
92
+
93
+ it 'should detect no problems' do
94
+ expect(problems).to have(0).problem
95
+ end
96
+ end
73
97
 
74
98
  context 'with parameters and no spaces' do
75
99
  let(:code) do
@@ -405,370 +429,8 @@ describe 'manifest_whitespace_class_name_single_space_after' do
405
429
  EOF
406
430
  end
407
431
 
408
- context 'with fix disabled' do
409
- it 'should detect a single problem' do
410
- expect(problems).to have(1).problem
411
- end
412
-
413
- it 'should create a error' do
414
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
415
- end
416
- end
417
-
418
- context 'with fix enabled' do
419
- before do
420
- PuppetLint.configuration.fix = true
421
- end
422
-
423
- after do
424
- PuppetLint.configuration.fix = false
425
- end
426
-
427
- it 'should detect a single problem' do
428
- expect(problems).to have(1).problem
429
- end
430
-
431
- it 'should not fix the manifest' do
432
- expect(problems).to contain_error(single_space_msg).on_line(6).in_column(14)
433
- end
434
- end
435
- end
436
- end
437
-
438
- describe 'manifest_whitespace_class_opening_curly_brace' do
439
- let(:opening_curly_brace_same_line_msg) { 'there should be a single space before the opening curly brace of a class body' }
440
-
441
- context 'with no spaces' do
442
- let(:code) do
443
- <<~EOF
444
- # example
445
- #
446
- # Main class, includes all other classes.
447
- #
448
-
449
- class example (
450
- String $content,
451
- ){
452
- class { 'example2':
453
- param1 => 'value1',
454
- }
455
- }
456
- EOF
457
- end
458
-
459
- context 'with fix disabled' do
460
- it 'should detect a single problem' do
461
- expect(problems).to have(1).problem
462
- end
463
-
464
- it 'should create a error' do
465
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(8).in_column(2)
466
- end
467
- end
468
-
469
- context 'with fix enabled' do
470
- before do
471
- PuppetLint.configuration.fix = true
472
- end
473
-
474
- after do
475
- PuppetLint.configuration.fix = false
476
- end
477
-
478
- it 'should detect a single problem' do
479
- expect(problems).to have(1).problem
480
- end
481
-
482
- it 'should create a error' do
483
- expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
484
- end
485
-
486
- it 'should add a space' do
487
- expect(manifest).to eq(
488
- <<~EOF,
489
- # example
490
- #
491
- # Main class, includes all other classes.
492
- #
493
-
494
- class example (
495
- String $content,
496
- ) {
497
- class { 'example2':
498
- param1 => 'value1',
499
- }
500
- }
501
- EOF
502
- )
503
- end
504
- end
505
- end
506
-
507
- context 'with two spaces' do
508
- let(:code) do
509
- <<~EOF
510
- # example
511
- #
512
- # Main class, includes all other classes.
513
- #
514
-
515
- class example (
516
- String $content,
517
- ) {
518
- class { 'example2':
519
- param1 => 'value1',
520
- }
521
- }
522
- EOF
523
- end
524
-
525
- context 'with fix disabled' do
526
- it 'should detect a single problem' do
527
- expect(problems).to have(1).problem
528
- end
529
-
530
- it 'should create a error' do
531
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(8).in_column(4)
532
- end
533
- end
534
-
535
- context 'with fix enabled' do
536
- before do
537
- PuppetLint.configuration.fix = true
538
- end
539
-
540
- after do
541
- PuppetLint.configuration.fix = false
542
- end
543
-
544
- it 'should detect a single problem' do
545
- expect(problems).to have(1).problem
546
- end
547
-
548
- it 'should create a error' do
549
- expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
550
- end
551
-
552
- it 'should remove a space' do
553
- expect(manifest).to eq(
554
- <<~EOF,
555
- # example
556
- #
557
- # Main class, includes all other classes.
558
- #
559
-
560
- class example (
561
- String $content,
562
- ) {
563
- class { 'example2':
564
- param1 => 'value1',
565
- }
566
- }
567
- EOF
568
- )
569
- end
570
- end
571
- end
572
-
573
- context 'with newline' do
574
- let(:code) do
575
- <<~EOF
576
- # example
577
- #
578
- # Main class, includes all other classes.
579
- #
580
-
581
- class example (
582
- String $content,
583
- )
584
- {
585
- class { 'example2':
586
- param1 => 'value1',
587
- }
588
- }
589
- EOF
590
- end
591
-
592
- context 'with fix disabled' do
593
- it 'should detect a single problem' do
594
- expect(problems).to have(1).problem
595
- end
596
-
597
- it 'should create a error' do
598
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
599
- end
600
- end
601
-
602
- context 'with fix enabled' do
603
- before do
604
- PuppetLint.configuration.fix = true
605
- end
606
-
607
- after do
608
- PuppetLint.configuration.fix = false
609
- end
610
-
611
- it 'should detect a single problem' do
612
- expect(problems).to have(1).problem
613
- end
614
-
615
- it 'should create a error' do
616
- expect(problems).to contain_fixed(opening_curly_brace_same_line_msg)
617
- end
618
-
619
- it 'should fix the newline' do
620
- expect(manifest).to eq(
621
- <<~EOF,
622
- # example
623
- #
624
- # Main class, includes all other classes.
625
- #
626
-
627
- class example (
628
- String $content,
629
- ) {
630
- class { 'example2':
631
- param1 => 'value1',
632
- }
633
- }
634
- EOF
635
- )
636
- end
637
- end
638
- end
639
-
640
- context 'with comment' do
641
- let(:code) do
642
- <<~EOF
643
- # example
644
- #
645
- # Main class, includes all other classes.
646
- #
647
-
648
- class example (
649
- String $content,
650
- ) # the class
651
- {
652
- class { 'example2':
653
- param1 => 'value1',
654
- }
655
- }
656
- EOF
657
- end
658
-
659
- context 'with fix disabled' do
660
- it 'should detect a single problem' do
661
- expect(problems).to have(1).problem
662
- end
663
-
664
- it 'should create a error' do
665
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
666
- end
667
- end
668
-
669
- context 'with fix enabled' do
670
- before do
671
- PuppetLint.configuration.fix = true
672
- end
673
-
674
- after do
675
- PuppetLint.configuration.fix = false
676
- end
677
-
678
- it 'should detect a single problem' do
679
- expect(problems).to have(1).problem
680
- end
681
-
682
- it 'should not fix the manifest' do
683
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(9).in_column(1)
684
- end
685
- end
686
- end
687
-
688
- context 'with good inherits' do
689
- let(:code) do
690
- <<~EOF
691
- # example
692
- #
693
- # Main class, includes all other classes.
694
- #
695
-
696
- class example (
697
- String $content,
698
- ) inherits other::example {
699
- class { 'example2':
700
- param1 => 'value1',
701
- }
702
- }
703
- EOF
704
- end
705
-
706
- context 'with fix disabled' do
707
- it 'should detect no problem' do
708
- expect(problems).to have(0).problems
709
- end
710
- end
711
- end
712
-
713
- context 'with bad inherits' do
714
- let(:code) do
715
- <<~EOF
716
- # example
717
- #
718
- # Main class, includes all other classes.
719
- #
720
-
721
- class example (
722
- String $content,
723
- ) inherits other::example{
724
- class { 'example2':
725
- param1 => 'value1',
726
- }
727
- }
728
- EOF
729
- end
730
-
731
- context 'with fix disabled' do
732
- it 'should detect a single problem' do
733
- expect(problems).to have(1).problem
734
- end
735
-
736
- it 'should create a error' do
737
- expect(problems).to contain_error(opening_curly_brace_same_line_msg).on_line(8).in_column(26)
738
- end
739
- end
740
-
741
- context 'with fix enabled' do
742
- before do
743
- PuppetLint.configuration.fix = true
744
- end
745
-
746
- after do
747
- PuppetLint.configuration.fix = false
748
- end
749
-
750
- it 'should detect a missing space' do
751
- expect(problems).to have(1).problem
752
- end
753
-
754
- it 'should add the space' do
755
- expect(manifest).to eq(
756
- <<~EOF,
757
- # example
758
- #
759
- # Main class, includes all other classes.
760
- #
761
-
762
- class example (
763
- String $content,
764
- ) inherits other::example {
765
- class { 'example2':
766
- param1 => 'value1',
767
- }
768
- }
769
- EOF
770
- )
771
- end
432
+ it 'should detect no problem' do
433
+ expect(problems).to have(0).problems
772
434
  end
773
435
  end
774
436
  end
@@ -67,242 +67,3 @@ describe 'manifest_whitespace_inherits_name_single_space_before' do
67
67
  end
68
68
  end
69
69
  end
70
-
71
- describe 'manifest_whitespace_inherits_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 brace' }
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 inherits other::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(38)
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 inherits other::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 inherits other::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(38)
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 inherits other::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 inherits other::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(38)
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 inherits other::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 inherits other::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(38)
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(38)
305
- end
306
- end
307
- end
308
- end