Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CodeSniffer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 45 additions & 1 deletion tests/Core/ErrorSuppressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public function testSuppressError()
$this->assertEquals(0, $numErrors);
$this->assertEquals(0, count($errors));

// Process with a PHPDoc block suppression.
$content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */';
$file = $phpcs->processFile('suppressionTest.php', $content);

$errors = $file->getErrors();
$numErrors = $file->getErrorCount();
$this->assertEquals(0, $numErrors);
$this->assertEquals(0, count($errors));

}//end testSuppressError()


Expand Down Expand Up @@ -86,6 +95,15 @@ public function testSuppressSomeErrors()
$this->assertEquals(1, $numErrors);
$this->assertEquals(1, count($errors));

// Process with a PHPDoc block suppression.
$content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$var = TRUE;';
$file = $phpcs->processFile('suppressionTest.php', $content);

$errors = $file->getErrors();
$numErrors = $file->getErrorCount();
$this->assertEquals(1, $numErrors);
$this->assertEquals(1, count($errors));

}//end testSuppressSomeErrors()


Expand Down Expand Up @@ -117,6 +135,15 @@ public function testSuppressWarning()
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));

// Process with a PHPDoc block suppression.
$content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** @codingStandardsIgnoreEnd */';
$file = $phpcs->processFile('suppressionTest.php', $content);

$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));

}//end testSuppressWarning()


Expand Down Expand Up @@ -147,7 +174,6 @@ public function testSuppressLine()
$numErrors = $file->getErrorCount();
$this->assertEquals(1, $numErrors);
$this->assertEquals(1, count($errors));

}//end testSuppressLine()


Expand Down Expand Up @@ -220,6 +246,15 @@ public function testSuppressScope()
$this->assertEquals(0, $numErrors);
$this->assertEquals(0, count($errors));

// Process with a PhpDoc Block suppression.
$content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$this->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()


Expand Down Expand Up @@ -260,6 +295,15 @@ public function testSuppressFile()
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));

// Process with a PhpDoc Block suppression.
$content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code';
$file = $phpcs->processFile('suppressionTest.php', $content);

$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));

}//end testSuppressFile()


Expand Down