@@ -81,6 +81,46 @@ public function testSuppressError()
81
81
$ this ->assertEquals (0 , $ numErrors );
82
82
$ this ->assertCount (0 , $ errors );
83
83
84
+ // Process with inline hash comment suppression.
85
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# phpcs:enable ' ;
86
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
87
+ $ file ->process ();
88
+
89
+ $ errors = $ file ->getErrors ();
90
+ $ numErrors = $ file ->getErrorCount ();
91
+ $ this ->assertEquals (0 , $ numErrors );
92
+ $ this ->assertCount (0 , $ errors );
93
+
94
+ // Process with multi-line inline hash comment suppression, tab-indented.
95
+ $ content = '<?php ' .PHP_EOL ."\t" .'# For reasons ' .PHP_EOL ."\t" .'# phpcs:disable ' .PHP_EOL ."\t" .'$var = FALSE; ' .PHP_EOL ."\t" .'# phpcs:enable ' ;
96
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
97
+ $ file ->process ();
98
+
99
+ $ errors = $ file ->getErrors ();
100
+ $ numErrors = $ file ->getErrorCount ();
101
+ $ this ->assertEquals (0 , $ numErrors );
102
+ $ this ->assertCount (0 , $ errors );
103
+
104
+ // Process with inline hash @ comment suppression.
105
+ $ content = '<?php ' .PHP_EOL .'# @phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# @phpcs:enable ' ;
106
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
107
+ $ file ->process ();
108
+
109
+ $ errors = $ file ->getErrors ();
110
+ $ numErrors = $ file ->getErrorCount ();
111
+ $ this ->assertEquals (0 , $ numErrors );
112
+ $ this ->assertCount (0 , $ errors );
113
+
114
+ // Process with inline hash comment suppression mixed case.
115
+ $ content = '<?php ' .PHP_EOL .'# PHPCS:Disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# pHPcs:enabLE ' ;
116
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
117
+ $ file ->process ();
118
+
119
+ $ errors = $ file ->getErrors ();
120
+ $ numErrors = $ file ->getErrorCount ();
121
+ $ this ->assertEquals (0 , $ numErrors );
122
+ $ this ->assertCount (0 , $ errors );
123
+
84
124
// Process with inline comment suppression (deprecated syntax).
85
125
$ content = '<?php ' .PHP_EOL .'// @codingStandardsIgnoreStart ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'// @codingStandardsIgnoreEnd ' ;
86
126
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -217,6 +257,26 @@ public function testSuppressSomeErrors()
217
257
$ this ->assertEquals (1 , $ numErrors );
218
258
$ this ->assertCount (1 , $ errors );
219
259
260
+ // Process with suppression (hash comment).
261
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# phpcs:enable ' .PHP_EOL .'$var = TRUE; ' ;
262
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
263
+ $ file ->process ();
264
+
265
+ $ errors = $ file ->getErrors ();
266
+ $ numErrors = $ file ->getErrorCount ();
267
+ $ this ->assertEquals (1 , $ numErrors );
268
+ $ this ->assertCount (1 , $ errors );
269
+
270
+ // Process with @ suppression (hash comment).
271
+ $ content = '<?php ' .PHP_EOL .'# @phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# @phpcs:enable ' .PHP_EOL .'$var = TRUE; ' ;
272
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
273
+ $ file ->process ();
274
+
275
+ $ errors = $ file ->getErrors ();
276
+ $ numErrors = $ file ->getErrorCount ();
277
+ $ this ->assertEquals (1 , $ numErrors );
278
+ $ this ->assertCount (1 , $ errors );
279
+
220
280
// Process with suppression (deprecated syntax).
221
281
$ content = '<?php ' .PHP_EOL .'// @codingStandardsIgnoreStart ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'// @codingStandardsIgnoreEnd ' .PHP_EOL .'$var = TRUE; ' ;
222
282
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -372,6 +432,26 @@ public function testSuppressLine()
372
432
$ this ->assertEquals (1 , $ numErrors );
373
433
$ this ->assertCount (1 , $ errors );
374
434
435
+ // Process with suppression on line before (hash comment).
436
+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
437
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
438
+ $ file ->process ();
439
+
440
+ $ errors = $ file ->getErrors ();
441
+ $ numErrors = $ file ->getErrorCount ();
442
+ $ this ->assertEquals (1 , $ numErrors );
443
+ $ this ->assertCount (1 , $ errors );
444
+
445
+ // Process with @ suppression on line before (hash comment).
446
+ $ content = '<?php ' .PHP_EOL .'# @phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
447
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
448
+ $ file ->process ();
449
+
450
+ $ errors = $ file ->getErrors ();
451
+ $ numErrors = $ file ->getErrorCount ();
452
+ $ this ->assertEquals (1 , $ numErrors );
453
+ $ this ->assertCount (1 , $ errors );
454
+
375
455
// Process with suppression on line before.
376
456
$ content = '<?php ' .PHP_EOL .'/* phpcs:ignore */ ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
377
457
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -432,6 +512,26 @@ public function testSuppressLine()
432
512
$ this ->assertEquals (1 , $ numErrors );
433
513
$ this ->assertCount (1 , $ errors );
434
514
515
+ // Process with suppression on same line (hash comment).
516
+ $ content = '<?php ' .PHP_EOL .'$var = FALSE; # phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' ;
517
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
518
+ $ file ->process ();
519
+
520
+ $ errors = $ file ->getErrors ();
521
+ $ numErrors = $ file ->getErrorCount ();
522
+ $ this ->assertEquals (1 , $ numErrors );
523
+ $ this ->assertCount (1 , $ errors );
524
+
525
+ // Process with @ suppression on same line (hash comment).
526
+ $ content = '<?php ' .PHP_EOL .'$var = FALSE; # @phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' ;
527
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
528
+ $ file ->process ();
529
+
530
+ $ errors = $ file ->getErrors ();
531
+ $ numErrors = $ file ->getErrorCount ();
532
+ $ this ->assertEquals (1 , $ numErrors );
533
+ $ this ->assertCount (1 , $ errors );
534
+
435
535
// Process with suppression on same line (deprecated syntax).
436
536
$ content = '<?php ' .PHP_EOL .'$var = FALSE; // @codingStandardsIgnoreLine ' .PHP_EOL .'$var = FALSE; ' ;
437
537
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -478,6 +578,16 @@ public function testNestedSuppressLine()
478
578
$ this ->assertEquals (0 , $ numErrors );
479
579
$ this ->assertCount (0 , $ errors );
480
580
581
+ // Process with disable/enable suppression and no single line suppression (hash comment).
582
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'# phpcs:enable ' ;
583
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
584
+ $ file ->process ();
585
+
586
+ $ errors = $ file ->getErrors ();
587
+ $ numErrors = $ file ->getErrorCount ();
588
+ $ this ->assertEquals (0 , $ numErrors );
589
+ $ this ->assertCount (0 , $ errors );
590
+
481
591
// Process with disable/enable suppression and no single line suppression (deprecated syntax).
482
592
$ content = '<?php ' .PHP_EOL .'// @codingStandardsIgnoreStart ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'// @codingStandardsIgnoreEnd ' ;
483
593
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -508,6 +618,16 @@ public function testNestedSuppressLine()
508
618
$ this ->assertEquals (0 , $ numErrors );
509
619
$ this ->assertCount (0 , $ errors );
510
620
621
+ // Process with line @ suppression nested within disable/enable @ suppression (hash comment).
622
+ $ content = '<?php ' .PHP_EOL .'# @phpcs:disable ' .PHP_EOL .'# @phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'# @phpcs:enable ' ;
623
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
624
+ $ file ->process ();
625
+
626
+ $ errors = $ file ->getErrors ();
627
+ $ numErrors = $ file ->getErrorCount ();
628
+ $ this ->assertEquals (0 , $ numErrors );
629
+ $ this ->assertCount (0 , $ errors );
630
+
511
631
// Process with line suppression nested within disable/enable suppression (deprecated syntax).
512
632
$ content = '<?php ' .PHP_EOL .'// @codingStandardsIgnoreStart ' .PHP_EOL .'// @codingStandardsIgnoreLine ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'// @codingStandardsIgnoreEnd ' ;
513
633
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -554,6 +674,16 @@ public function testSuppressScope()
554
674
$ this ->assertEquals (0 , $ numErrors );
555
675
$ this ->assertCount (0 , $ errors );
556
676
677
+ // Process with suppression (hash comment).
678
+ $ content = '<?php ' .PHP_EOL .'class MyClass() { ' .PHP_EOL .'#phpcs:disable ' .PHP_EOL .'function myFunction() { ' .PHP_EOL .'#phpcs:enable ' .PHP_EOL .'$this->foo(); ' .PHP_EOL .'} ' .PHP_EOL .'} ' ;
679
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
680
+ $ file ->process ();
681
+
682
+ $ errors = $ file ->getErrors ();
683
+ $ numErrors = $ file ->getErrorCount ();
684
+ $ this ->assertEquals (0 , $ numErrors );
685
+ $ this ->assertCount (0 , $ errors );
686
+
557
687
// Process with suppression.
558
688
$ content = '<?php ' .PHP_EOL .'class MyClass() { ' .PHP_EOL .'//@phpcs:disable ' .PHP_EOL .'function myFunction() { ' .PHP_EOL .'//@phpcs:enable ' .PHP_EOL .'$this->foo(); ' .PHP_EOL .'} ' .PHP_EOL .'} ' ;
559
689
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -647,6 +777,26 @@ public function testSuppressFile()
647
777
$ this ->assertEquals (0 , $ numWarnings );
648
778
$ this ->assertCount (0 , $ warnings );
649
779
780
+ // Process with suppression (hash comment).
781
+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignoreFile ' .PHP_EOL .'//TODO: write some code ' ;
782
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
783
+ $ file ->process ();
784
+
785
+ $ warnings = $ file ->getWarnings ();
786
+ $ numWarnings = $ file ->getWarningCount ();
787
+ $ this ->assertEquals (0 , $ numWarnings );
788
+ $ this ->assertCount (0 , $ warnings );
789
+
790
+ // Process with @ suppression (hash comment).
791
+ $ content = '<?php ' .PHP_EOL .'# @phpcs:ignoreFile ' .PHP_EOL .'//TODO: write some code ' ;
792
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
793
+ $ file ->process ();
794
+
795
+ $ warnings = $ file ->getWarnings ();
796
+ $ numWarnings = $ file ->getWarningCount ();
797
+ $ this ->assertEquals (0 , $ numWarnings );
798
+ $ this ->assertCount (0 , $ warnings );
799
+
650
800
// Process with suppression (deprecated syntax).
651
801
$ content = '<?php ' .PHP_EOL .'// @codingStandardsIgnoreFile ' .PHP_EOL .'//TODO: write some code ' ;
652
802
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -780,6 +930,20 @@ public function testDisableSelected()
780
930
$ this ->assertEquals (0 , $ numWarnings );
781
931
$ this ->assertCount (0 , $ warnings );
782
932
933
+ // Suppress a single sniff with reason (hash comment).
934
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable Generic.Commenting.Todo -- for reasons ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' ;
935
+ $ file = new DummyFile ($ content , $ ruleset , $ config );
936
+ $ file ->process ();
937
+
938
+ $ errors = $ file ->getErrors ();
939
+ $ numErrors = $ file ->getErrorCount ();
940
+ $ warnings = $ file ->getWarnings ();
941
+ $ numWarnings = $ file ->getWarningCount ();
942
+ $ this ->assertEquals (1 , $ numErrors );
943
+ $ this ->assertCount (1 , $ errors );
944
+ $ this ->assertEquals (0 , $ numWarnings );
945
+ $ this ->assertCount (0 , $ warnings );
946
+
783
947
// Suppress multiple sniffs.
784
948
$ content = '<?php ' .PHP_EOL .'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' ;
785
949
$ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -942,7 +1106,7 @@ public function testEnableSelected()
942
1106
$ this ->assertCount (1 , $ warnings );
943
1107
944
1108
// Suppress multiple sniffs and re-enable one.
945
- $ content = '<?php ' .PHP_EOL .'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'// phpcs:enable Generic.Commenting.Todo ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'$var = FALSE; ' ;
1109
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'# phpcs:enable Generic.Commenting.Todo ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'$var = FALSE; ' ;
946
1110
$ file = new DummyFile ($ content , $ ruleset , $ config );
947
1111
$ file ->process ();
948
1112
@@ -998,7 +1162,7 @@ public function testEnableSelected()
998
1162
$ this ->assertCount (1 , $ warnings );
999
1163
1000
1164
// Suppress a category and re-enable a whole standard.
1001
- $ content = '<?php ' .PHP_EOL .'// phpcs:disable Generic.Commenting ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'// phpcs:enable Generic ' .PHP_EOL .'//TODO: write some code ' ;
1165
+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable Generic.Commenting ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' .PHP_EOL .'# phpcs:enable Generic ' .PHP_EOL .'//TODO: write some code ' ;
1002
1166
$ file = new DummyFile ($ content , $ ruleset , $ config );
1003
1167
$ file ->process ();
1004
1168
@@ -1143,7 +1307,7 @@ public function testIgnoreSelected()
1143
1307
$ this ->assertCount (0 , $ warnings );
1144
1308
1145
1309
// Suppress a category of sniffs.
1146
- $ content = '<?php ' .PHP_EOL .'// phpcs:ignore Generic.Commenting ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' ;
1310
+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignore Generic.Commenting ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' ;
1147
1311
$ file = new DummyFile ($ content , $ ruleset , $ config );
1148
1312
$ file ->process ();
1149
1313
0 commit comments