Skip to content

Commit

Permalink
Squiz/BlockComment: fix issue with PHPCS annotations causing the comm…
Browse files Browse the repository at this point in the history
…ent closer to be misidentified.

Whether something was identified as a comment line was based on the token code being the same.
This did not allow for PHPCS annotations to be included in block comments as those have a different token code.

This resulted in comments being "cut short", i.e. the line above a PHPCS annotation being seen as the last line in a comment and subsequent comment lines being ignored, resulting in incorrect `Comment closer must be on a new line` and `Empty line required after block comment` notices.

Fixes 1918
  • Loading branch information
jrfnl committed Feb 27, 2018
1 parent d735ce8 commit 37e5b0b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public function process(File $phpcsFile, $stackPtr)

// Construct the comment into an array.
while (($nextComment = $phpcsFile->findNext(T_WHITESPACE, ($nextComment + 1), null, true)) !== false) {
if ($tokens[$nextComment]['code'] !== $tokens[$stackPtr]['code']) {
if ($tokens[$nextComment]['code'] !== $tokens[$stackPtr]['code']
&& isset(Tokens::$phpcsCommentTokens[$tokens[$nextComment]['code']]) === false
) {
// Found the next bit of code.
break;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,14 @@ class TabTest {
// Mid-line inline comment style should not be auto-fixed.
if (true || /* test */ -1 == $b) {}
$y = 10 + /* test */ -2;

/*
* When the comment contains PHPCS annotations, the comment closer was being misidentified.
* phpcs:disable Standard.Category.Sniff
*/

/*
* When the comment contains PHPCS annotations, the comment closer was being misidentified.
* See: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1918}
* @phpcs:disable Standard.Category.Sniff
*/
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,14 @@ class TabTest {
// Mid-line inline comment style should not be auto-fixed.
if (true || /* test */ -1 == $b) {}
$y = 10 + /* test */ -2;

/*
* When the comment contains PHPCS annotations, the comment closer was being misidentified.
* phpcs:disable Standard.Category.Sniff
*/

/*
* When the comment contains PHPCS annotations, the comment closer was being misidentified.
* See: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1918}
* @phpcs:disable Standard.Category.Sniff
*/

0 comments on commit 37e5b0b

Please sign in to comment.