From 8909858f9cbfc16ad1b4a2a4b61ff7a3db843251 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 24 Feb 2020 08:11:52 +1100 Subject: [PATCH] Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock --- package.xml | 1 + src/Tokenizers/Tokenizer.php | 6 +++++- tests/Core/ErrorSuppressionTest.php | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/package.xml b/package.xml index bda0f37f75..7894fa1bb6 100644 --- a/package.xml +++ b/package.xml @@ -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 diff --git a/src/Tokenizers/Tokenizer.php b/src/Tokenizers/Tokenizer.php index 850b7dbb17..66f7885c81 100644 --- a/src/Tokenizers/Tokenizer.php +++ b/src/Tokenizers/Tokenizer.php @@ -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']) === '') ) { @@ -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; } @@ -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']) === '') ) { diff --git a/tests/Core/ErrorSuppressionTest.php b/tests/Core/ErrorSuppressionTest.php index ad788b3c54..f031b334bb 100644 --- a/tests/Core/ErrorSuppressionTest.php +++ b/tests/Core/ErrorSuppressionTest.php @@ -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); @@ -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 = 'process(); @@ -399,6 +402,16 @@ public function testSuppressLine() $this->assertEquals(1, $numErrors); $this->assertCount(1, $errors); + // Process with @ suppression on line before inside docblock. + $content = 'process(); + + $errors = $file->getErrors(); + $numErrors = $file->getErrorCount(); + $this->assertEquals(0, $numErrors); + $this->assertCount(0, $errors); + // Process with suppression on same line. $content = '