Skip to content

Commit 991fa81

Browse files
committed
Generic/DocComment: bug fix - don't remove ignore annotations when fixing
The code sample included in the tests would previously result in an "There must be a single blank line after a tag group" error, even though there _is_ a blank line after the `@codeCoverageIgnore` tag. The auto-fixer would subsequently fix this by removing the `@phpcs:disable` comment + the blank line after it. Fixed now. Includes test.
1 parent 5ef2b66 commit 991fa81

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\Sniff;
14+
use PHP_CodeSniffer\Util\Tokens;
1415

1516
class DocCommentSniff implements Sniff
1617
{
@@ -280,9 +281,12 @@ public function process(File $phpcsFile, $stackPtr)
280281
}
281282

282283
// Check that there was single blank line after the tag block
283-
// but account for a multi-line tag comments.
284+
// but account for multi-line tag comments.
285+
$find = Tokens::$phpcsCommentTokens;
286+
$find[T_DOC_COMMENT_TAG] = T_DOC_COMMENT_TAG;
287+
284288
$lastTag = $group[$pos];
285-
$next = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($lastTag + 3), $commentEnd);
289+
$next = $phpcsFile->findNext($find, ($lastTag + 3), $commentEnd);
286290
if ($next !== false) {
287291
$prev = $phpcsFile->findPrevious([T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING], ($next - 1), $commentStart);
288292
if ($tokens[$next]['line'] !== ($tokens[$prev]['line'] + 2)) {

src/Standards/Generic/Tests/Commenting/DocCommentUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,14 @@
249249
* @link http://pear.php.net/package/PHP_CodeSniffer
250250
*/
251251

252+
/**
253+
* Do something.
254+
*
255+
* @codeCoverageIgnore
256+
*
257+
* @phpcs:disable Stnd.Cat.SniffName
258+
*
259+
* @return void
260+
*/
261+
252262
/** No docblock close tag. Must be last test without new line.

src/Standards/Generic/Tests/Commenting/DocCommentUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,14 @@
254254
* @link http://pear.php.net/package/PHP_CodeSniffer
255255
*/
256256

257+
/**
258+
* Do something.
259+
*
260+
* @codeCoverageIgnore
261+
*
262+
* @phpcs:disable Stnd.Cat.SniffName
263+
*
264+
* @return void
265+
*/
266+
257267
/** No docblock close tag. Must be last test without new line.

0 commit comments

Comments
 (0)