Skip to content

Commit b50cf54

Browse files
authored
Merge pull request #91 from PHPCSStandards/feature/generic-doccomment-fixer-removes-ignore-annotations
Generic/DocComment: bug fix - don't remove ignore annotations when fixing
2 parents b1db1a8 + 9397de6 commit b50cf54

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ The file documents changes to the PHP_CodeSniffer project.
155155
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
156156
- Fixed bug #3877 : Filter names can be case-sensitive. The -h help text will now display the correct case for the available filters
157157
- Thanks to @simonsan for the patch
158+
- Fixed bug #3893 : Generic/DocComment : the SpacingAfterTagGroup fixer could accidentally remove ignore annotations
159+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
158160
- Fixed bug #3906 : Tokenizer/CSS: fixed a bug related to the unsupported slash comment syntax
159161
- Thanks to Dan Wallis (@fredden) for the patch
160162

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)