Skip to content

Commit 8909858

Browse files
committed
Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
1 parent db617f1 commit 8909858

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3535
- Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase
3636
- Fixed bug #2853 : Undefined variable error when using Info report
3737
-- Thanks to Juliette Reinders Folmer for the patch
38+
- Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
3839
</notes>
3940
<contents>
4041
<dir name="/">

src/Tokenizers/Tokenizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ private function createPositionMap()
332332
}
333333

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

341342
$lineHasOtherTokens = true;
342343

343-
if ($this->tokens[$prev]['code'] === T_OPEN_TAG) {
344+
if ($this->tokens[$prev]['code'] === T_OPEN_TAG
345+
|| $this->tokens[$prev]['code'] === T_DOC_COMMENT_STAR
346+
) {
344347
continue;
345348
}
346349

@@ -367,6 +370,7 @@ private function createPositionMap()
367370
}
368371

369372
if ($this->tokens[$next]['code'] === T_WHITESPACE
373+
|| $this->tokens[$next]['code'] === T_DOC_COMMENT_WHITESPACE
370374
|| ($this->tokens[$next]['code'] === T_INLINE_HTML
371375
&& trim($this->tokens[$next]['content']) === '')
372376
) {

tests/Core/ErrorSuppressionTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ public function testSuppressLine()
335335
{
336336
$config = new Config();
337337
$config->standards = ['Generic'];
338-
$config->sniffs = ['Generic.PHP.LowerCaseConstant'];
338+
$config->sniffs = [
339+
'Generic.PHP.LowerCaseConstant',
340+
'Generic.Files.LineLength',
341+
];
339342

340343
$ruleset = new Ruleset($config);
341344

@@ -379,7 +382,7 @@ public function testSuppressLine()
379382
$this->assertEquals(1, $numErrors);
380383
$this->assertCount(1, $errors);
381384

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

405+
// Process with @ suppression on line before inside docblock.
406+
$content = '<?php '.PHP_EOL.'/**'.PHP_EOL.' * Comment here'.PHP_EOL.' * @phpcs:ignore'.PHP_EOL.' * '.str_repeat('a ', 50).PHP_EOL.'*/';
407+
$file = new DummyFile($content, $ruleset, $config);
408+
$file->process();
409+
410+
$errors = $file->getErrors();
411+
$numErrors = $file->getErrorCount();
412+
$this->assertEquals(0, $numErrors);
413+
$this->assertCount(0, $errors);
414+
402415
// Process with suppression on same line.
403416
$content = '<?php '.PHP_EOL.'$var = FALSE; // phpcs:ignore'.PHP_EOL.'$var = FALSE;';
404417
$file = new DummyFile($content, $ruleset, $config);

0 commit comments

Comments
 (0)