diff --git a/CodeSniffer/File.php b/CodeSniffer/File.php index d59eddab0b..6e98a9363f 100644 --- a/CodeSniffer/File.php +++ b/CodeSniffer/File.php @@ -485,7 +485,7 @@ public function start($contents=null) foreach ($this->_tokens as $stackPtr => $token) { // Check for ignored lines. if ($token['code'] === T_COMMENT - || $token['code'] === T_DOC_COMMENT + || $token['code'] === T_DOC_COMMENT_TAG || ($inTests === true && $token['code'] === T_INLINE_HTML) ) { if (strpos($token['content'], '@codingStandards') !== false) { @@ -1603,7 +1603,7 @@ private static function _createPositionMap(&$tokens, $tokenizer, $eolChar, $enco } if ($tokens[$i]['code'] === T_COMMENT - || $tokens[$i]['code'] === T_DOC_COMMENT + || $tokens[$i]['code'] === T_DOC_COMMENT_TAG || ($inTests === true && $tokens[$i]['code'] === T_INLINE_HTML) ) { if (strpos($tokens[$i]['content'], '@codingStandards') !== false) { diff --git a/tests/Core/ErrorSuppressionTest.php b/tests/Core/ErrorSuppressionTest.php index fcef01c726..0fad8ff1a6 100644 --- a/tests/Core/ErrorSuppressionTest.php +++ b/tests/Core/ErrorSuppressionTest.php @@ -55,6 +55,15 @@ public function testSuppressError() $this->assertEquals(0, $numErrors); $this->assertEquals(0, count($errors)); + // Process with a PHPDoc block suppression. + $content = 'processFile('suppressionTest.php', $content); + + $errors = $file->getErrors(); + $numErrors = $file->getErrorCount(); + $this->assertEquals(0, $numErrors); + $this->assertEquals(0, count($errors)); + }//end testSuppressError() @@ -86,6 +95,15 @@ public function testSuppressSomeErrors() $this->assertEquals(1, $numErrors); $this->assertEquals(1, count($errors)); + // Process with a PHPDoc block suppression. + $content = 'processFile('suppressionTest.php', $content); + + $errors = $file->getErrors(); + $numErrors = $file->getErrorCount(); + $this->assertEquals(1, $numErrors); + $this->assertEquals(1, count($errors)); + }//end testSuppressSomeErrors() @@ -117,6 +135,15 @@ public function testSuppressWarning() $this->assertEquals(0, $numWarnings); $this->assertEquals(0, count($warnings)); + // Process with a PHPDoc block suppression. + $content = 'processFile('suppressionTest.php', $content); + + $warnings = $file->getWarnings(); + $numWarnings = $file->getWarningCount(); + $this->assertEquals(0, $numWarnings); + $this->assertEquals(0, count($warnings)); + }//end testSuppressWarning() @@ -147,7 +174,6 @@ public function testSuppressLine() $numErrors = $file->getErrorCount(); $this->assertEquals(1, $numErrors); $this->assertEquals(1, count($errors)); - }//end testSuppressLine() @@ -220,6 +246,15 @@ public function testSuppressScope() $this->assertEquals(0, $numErrors); $this->assertEquals(0, count($errors)); + // Process with a PhpDoc Block suppression. + $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; + $file = $phpcs->processFile('suppressionTest.php', $content); + + $errors = $file->getErrors(); + $numErrors = $file->getErrorCount(); + $this->assertEquals(0, $numErrors); + $this->assertEquals(0, count($errors)); + }//end testSuppressScope() @@ -260,6 +295,15 @@ public function testSuppressFile() $this->assertEquals(0, $numWarnings); $this->assertEquals(0, count($warnings)); + // Process with a PhpDoc Block suppression. + $content = 'processFile('suppressionTest.php', $content); + + $warnings = $file->getWarnings(); + $numWarnings = $file->getWarningCount(); + $this->assertEquals(0, $numWarnings); + $this->assertEquals(0, count($warnings)); + }//end testSuppressFile()