Skip to content

Commit

Permalink
Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Feb 23, 2020
1 parent db617f1 commit 8909858
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase
- Fixed bug #2853 : Undefined variable error when using Info report
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
</notes>
<contents>
<dir name="/">
Expand Down
6 changes: 5 additions & 1 deletion src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ private function createPositionMap()
}

if ($this->tokens[$prev]['code'] === T_WHITESPACE
|| $this->tokens[$prev]['code'] === T_DOC_COMMENT_WHITESPACE
|| ($this->tokens[$prev]['code'] === T_INLINE_HTML
&& trim($this->tokens[$prev]['content']) === '')
) {
Expand All @@ -340,7 +341,9 @@ private function createPositionMap()

$lineHasOtherTokens = true;

if ($this->tokens[$prev]['code'] === T_OPEN_TAG) {
if ($this->tokens[$prev]['code'] === T_OPEN_TAG
|| $this->tokens[$prev]['code'] === T_DOC_COMMENT_STAR
) {
continue;
}

Expand All @@ -367,6 +370,7 @@ private function createPositionMap()
}

if ($this->tokens[$next]['code'] === T_WHITESPACE
|| $this->tokens[$next]['code'] === T_DOC_COMMENT_WHITESPACE
|| ($this->tokens[$next]['code'] === T_INLINE_HTML
&& trim($this->tokens[$next]['content']) === '')
) {
Expand Down
17 changes: 15 additions & 2 deletions tests/Core/ErrorSuppressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ public function testSuppressLine()
{
$config = new Config();
$config->standards = ['Generic'];
$config->sniffs = ['Generic.PHP.LowerCaseConstant'];
$config->sniffs = [
'Generic.PHP.LowerCaseConstant',
'Generic.Files.LineLength',
];

$ruleset = new Ruleset($config);

Expand Down Expand Up @@ -379,7 +382,7 @@ public function testSuppressLine()
$this->assertEquals(1, $numErrors);
$this->assertCount(1, $errors);

// Process with @ suppression on line before.
// Process with @ suppression on line before.
$content = '<?php '.PHP_EOL.'/* @phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;';
$file = new DummyFile($content, $ruleset, $config);
$file->process();
Expand All @@ -399,6 +402,16 @@ public function testSuppressLine()
$this->assertEquals(1, $numErrors);
$this->assertCount(1, $errors);

// Process with @ suppression on line before inside docblock.
$content = '<?php '.PHP_EOL.'/**'.PHP_EOL.' * Comment here'.PHP_EOL.' * @phpcs:ignore'.PHP_EOL.' * '.str_repeat('a ', 50).PHP_EOL.'*/';
$file = new DummyFile($content, $ruleset, $config);
$file->process();

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

// Process with suppression on same line.
$content = '<?php '.PHP_EOL.'$var = FALSE; // phpcs:ignore'.PHP_EOL.'$var = FALSE;';
$file = new DummyFile($content, $ruleset, $config);
Expand Down

0 comments on commit 8909858

Please sign in to comment.