Skip to content

Commit

Permalink
Squiz/FunctionSpacing: fixer is broken with doc comment on closing br…
Browse files Browse the repository at this point in the history
…ace line (#784)

The fixer in Squiz.WhiteSpace.FunctionSpacing gets confused when there is a doc comment on the closing brace line.

Generally speaking this sniff doesn't care about other content on the same line as the function declaration.

But in the case of a "trailing" docblock, this meant that the sniff was adding the new lines _within_ the doc block, which, in turn, meant it would still not see the "blank lines after" in the next loop, as the added lines would be seen as doc comment lines, not blank lines. Hence, the fixer conflict.

Fixed now.
  • Loading branch information
klausi authored Jan 12, 2025
1 parent ba08a82 commit aebd84b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public function process(File $phpcsFile, $stackPtr)

// Allow for comments on the same line as the closer.
for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) {
// A doc comment belongs to the next statement and must not be on
// this line.
if ($tokens[$nextLineToken]['code'] === T_DOC_COMMENT_OPEN_TAG) {
break;
}

if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
break;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,14 @@ echo 'this line belongs with the #3904 test';

function Foo() {} function bar($name){}
echo 'this line belongs with the #3904 test';


/**
* foo.
*/
function a() {
}/**
* foo.
*/
function b() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,17 @@ function Foo() {} function bar($name){}


echo 'this line belongs with the #3904 test';


/**
* foo.
*/
function a() {
}


/**
* foo.
*/
function b() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function getErrorList($testFile='')
566 => 1,
580 => 2,
583 => 3,
591 => 1,
];

case 'FunctionSpacingUnitTest.2.inc':
Expand Down

0 comments on commit aebd84b

Please sign in to comment.