@@ -81,6 +81,46 @@ public function testSuppressError()
8181 $ this ->assertEquals (0 , $ numErrors );
8282 $ this ->assertCount (0 , $ errors );
8383
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+
84124 // Process with block comment suppression.
85125 $ content = '<?php ' .PHP_EOL .'/* phpcs:disable */ ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'/* phpcs:enable */ ' ;
86126 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -177,6 +217,26 @@ public function testSuppressSomeErrors()
177217 $ this ->assertEquals (1 , $ numErrors );
178218 $ this ->assertCount (1 , $ errors );
179219
220+ // Process with suppression (hash comment).
221+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# phpcs:enable ' .PHP_EOL .'$var = TRUE; ' ;
222+ $ file = new DummyFile ($ content , $ ruleset , $ config );
223+ $ file ->process ();
224+
225+ $ errors = $ file ->getErrors ();
226+ $ numErrors = $ file ->getErrorCount ();
227+ $ this ->assertEquals (1 , $ numErrors );
228+ $ this ->assertCount (1 , $ errors );
229+
230+ // Process with @ suppression (hash comment).
231+ $ content = '<?php ' .PHP_EOL .'# @phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'# @phpcs:enable ' .PHP_EOL .'$var = TRUE; ' ;
232+ $ file = new DummyFile ($ content , $ ruleset , $ config );
233+ $ file ->process ();
234+
235+ $ errors = $ file ->getErrors ();
236+ $ numErrors = $ file ->getErrorCount ();
237+ $ this ->assertEquals (1 , $ numErrors );
238+ $ this ->assertCount (1 , $ errors );
239+
180240 // Process with a PHPDoc block suppression.
181241 $ content = '<?php ' .PHP_EOL .'/** phpcs:disable */ ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'/** phpcs:enable */ ' .PHP_EOL .'$var = TRUE; ' ;
182242 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -292,6 +352,26 @@ public function testSuppressLine()
292352 $ this ->assertEquals (1 , $ numErrors );
293353 $ this ->assertCount (1 , $ errors );
294354
355+ // Process with suppression on line before (hash comment).
356+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
357+ $ file = new DummyFile ($ content , $ ruleset , $ config );
358+ $ file ->process ();
359+
360+ $ errors = $ file ->getErrors ();
361+ $ numErrors = $ file ->getErrorCount ();
362+ $ this ->assertEquals (1 , $ numErrors );
363+ $ this ->assertCount (1 , $ errors );
364+
365+ // Process with @ suppression on line before (hash comment).
366+ $ content = '<?php ' .PHP_EOL .'# @phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
367+ $ file = new DummyFile ($ content , $ ruleset , $ config );
368+ $ file ->process ();
369+
370+ $ errors = $ file ->getErrors ();
371+ $ numErrors = $ file ->getErrorCount ();
372+ $ this ->assertEquals (1 , $ numErrors );
373+ $ this ->assertCount (1 , $ errors );
374+
295375 // Process with suppression on line before.
296376 $ content = '<?php ' .PHP_EOL .'/* phpcs:ignore */ ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = FALSE; ' ;
297377 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -342,6 +422,26 @@ public function testSuppressLine()
342422 $ this ->assertEquals (1 , $ numErrors );
343423 $ this ->assertCount (1 , $ errors );
344424
425+ // Process with suppression on same line (hash comment).
426+ $ content = '<?php ' .PHP_EOL .'$var = FALSE; # phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' ;
427+ $ file = new DummyFile ($ content , $ ruleset , $ config );
428+ $ file ->process ();
429+
430+ $ errors = $ file ->getErrors ();
431+ $ numErrors = $ file ->getErrorCount ();
432+ $ this ->assertEquals (1 , $ numErrors );
433+ $ this ->assertCount (1 , $ errors );
434+
435+ // Process with @ suppression on same line (hash comment).
436+ $ content = '<?php ' .PHP_EOL .'$var = FALSE; # @phpcs:ignore ' .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+
345445 }//end testSuppressLine()
346446
347447
@@ -378,6 +478,16 @@ public function testNestedSuppressLine()
378478 $ this ->assertEquals (0 , $ numErrors );
379479 $ this ->assertCount (0 , $ errors );
380480
481+ // Process with disable/enable suppression and no single line suppression (hash comment).
482+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'# phpcs:enable ' ;
483+ $ file = new DummyFile ($ content , $ ruleset , $ config );
484+ $ file ->process ();
485+
486+ $ errors = $ file ->getErrors ();
487+ $ numErrors = $ file ->getErrorCount ();
488+ $ this ->assertEquals (0 , $ numErrors );
489+ $ this ->assertCount (0 , $ errors );
490+
381491 // Process with line suppression nested within disable/enable suppression.
382492 $ content = '<?php ' .PHP_EOL .'// phpcs:disable ' .PHP_EOL .'// phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'// phpcs:enable ' ;
383493 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -398,6 +508,16 @@ public function testNestedSuppressLine()
398508 $ this ->assertEquals (0 , $ numErrors );
399509 $ this ->assertCount (0 , $ errors );
400510
511+ // Process with line @ suppression nested within disable/enable @ suppression (hash comment).
512+ $ content = '<?php ' .PHP_EOL .'# @phpcs:disable ' .PHP_EOL .'# @phpcs:ignore ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'$var = TRUE; ' .PHP_EOL .'# @phpcs:enable ' ;
513+ $ file = new DummyFile ($ content , $ ruleset , $ config );
514+ $ file ->process ();
515+
516+ $ errors = $ file ->getErrors ();
517+ $ numErrors = $ file ->getErrorCount ();
518+ $ this ->assertEquals (0 , $ numErrors );
519+ $ this ->assertCount (0 , $ errors );
520+
401521 }//end testNestedSuppressLine()
402522
403523
@@ -434,6 +554,16 @@ public function testSuppressScope()
434554 $ this ->assertEquals (0 , $ numErrors );
435555 $ this ->assertCount (0 , $ errors );
436556
557+ // Process with suppression (hash comment).
558+ $ 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+ $ file = new DummyFile ($ content , $ ruleset , $ config );
560+ $ file ->process ();
561+
562+ $ errors = $ file ->getErrors ();
563+ $ numErrors = $ file ->getErrorCount ();
564+ $ this ->assertEquals (0 , $ numErrors );
565+ $ this ->assertCount (0 , $ errors );
566+
437567 // Process with suppression.
438568 $ 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 .'} ' ;
439569 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -508,6 +638,26 @@ public function testSuppressFile()
508638 $ this ->assertEquals (0 , $ numWarnings );
509639 $ this ->assertCount (0 , $ warnings );
510640
641+ // Process with suppression (hash comment).
642+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignoreFile ' .PHP_EOL .'//TODO: write some code ' ;
643+ $ file = new DummyFile ($ content , $ ruleset , $ config );
644+ $ file ->process ();
645+
646+ $ warnings = $ file ->getWarnings ();
647+ $ numWarnings = $ file ->getWarningCount ();
648+ $ this ->assertEquals (0 , $ numWarnings );
649+ $ this ->assertCount (0 , $ warnings );
650+
651+ // Process with @ suppression (hash comment).
652+ $ content = '<?php ' .PHP_EOL .'# @phpcs:ignoreFile ' .PHP_EOL .'//TODO: write some code ' ;
653+ $ file = new DummyFile ($ content , $ ruleset , $ config );
654+ $ file ->process ();
655+
656+ $ warnings = $ file ->getWarnings ();
657+ $ numWarnings = $ file ->getWarningCount ();
658+ $ this ->assertEquals (0 , $ numWarnings );
659+ $ this ->assertCount (0 , $ warnings );
660+
511661 // Process mixed case.
512662 $ content = '<?php ' .PHP_EOL .'// PHPCS:Ignorefile ' .PHP_EOL .'//TODO: write some code ' ;
513663 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -591,6 +741,20 @@ public function testDisableSelected()
591741 $ this ->assertEquals (0 , $ numWarnings );
592742 $ this ->assertCount (0 , $ warnings );
593743
744+ // Suppress a single sniff with reason (hash comment).
745+ $ content = '<?php ' .PHP_EOL .'# phpcs:disable Generic.Commenting.Todo -- for reasons ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' ;
746+ $ file = new DummyFile ($ content , $ ruleset , $ config );
747+ $ file ->process ();
748+
749+ $ errors = $ file ->getErrors ();
750+ $ numErrors = $ file ->getErrorCount ();
751+ $ warnings = $ file ->getWarnings ();
752+ $ numWarnings = $ file ->getWarningCount ();
753+ $ this ->assertEquals (1 , $ numErrors );
754+ $ this ->assertCount (1 , $ errors );
755+ $ this ->assertEquals (0 , $ numWarnings );
756+ $ this ->assertCount (0 , $ warnings );
757+
594758 // Suppress multiple sniffs.
595759 $ content = '<?php ' .PHP_EOL .'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' .PHP_EOL .'$var = FALSE; ' .PHP_EOL .'//TODO: write some code ' ;
596760 $ file = new DummyFile ($ content , $ ruleset , $ config );
@@ -753,7 +917,7 @@ public function testEnableSelected()
753917 $ this ->assertCount (1 , $ warnings );
754918
755919 // Suppress multiple sniffs and re-enable one.
756- $ 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; ' ;
920+ $ 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; ' ;
757921 $ file = new DummyFile ($ content , $ ruleset , $ config );
758922 $ file ->process ();
759923
@@ -809,7 +973,7 @@ public function testEnableSelected()
809973 $ this ->assertCount (1 , $ warnings );
810974
811975 // Suppress a category and re-enable a whole standard.
812- $ 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 ' ;
976+ $ 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 ' ;
813977 $ file = new DummyFile ($ content , $ ruleset , $ config );
814978 $ file ->process ();
815979
@@ -954,7 +1118,7 @@ public function testIgnoreSelected()
9541118 $ this ->assertCount (0 , $ warnings );
9551119
9561120 // Suppress a category of sniffs.
957- $ content = '<?php ' .PHP_EOL .'// phpcs:ignore Generic.Commenting ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' ;
1121+ $ content = '<?php ' .PHP_EOL .'# phpcs:ignore Generic.Commenting ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' .PHP_EOL .'$var = FALSE; //TODO: write some code ' ;
9581122 $ file = new DummyFile ($ content , $ ruleset , $ config );
9591123 $ file ->process ();
9601124
0 commit comments