Skip to content

Commit

Permalink
fix(FunctionSpacing): Fixer is broken with doc comment on closing bra…
Browse files Browse the repository at this point in the history
…ce line
  • Loading branch information
klausi committed Jan 11, 2025
1 parent ba08a82 commit f636fe5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ 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;
}

Check failure on line 156 in src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php

View workflow job for this annotation

GitHub Actions / PHP: 7.4 (Linux)

No blank line found after control structure
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 f636fe5

Please sign in to comment.