Skip to content

Squiz/FunctionSpacing: fix regression - only look at first docblock #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,18 @@ public function process(File $phpcsFile, $stackPtr)
}

// Skip past function docblocks and attributes.
$prev = $startOfDeclarationLine;
// Only the first docblock is a function docblock. Other docblocks should be disregarded.
$prev = $startOfDeclarationLine;
$seenDocblock = false;
if ($startOfDeclarationLine > 0) {
for ($prev = ($startOfDeclarationLine - 1); $prev > 0; $prev--) {
if ($tokens[$prev]['code'] === T_WHITESPACE) {
continue;
}

if ($tokens[$prev]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
$prev = $tokens[$prev]['comment_opener'];
if ($seenDocblock === false && $tokens[$prev]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
$prev = $tokens[$prev]['comment_opener'];
$seenDocblock = true;
continue;
}

Expand Down
24 changes: 24 additions & 0 deletions src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,27 @@ class SilenceBeforeErrorIfPreviousThingWasAFunctionBug

}//end blankLineDetectionB()
}//end class

// Issue #945.
class OnlyAcceptFirstDocblockAsBelongingWithFunction {
/**
* Superfluous docblock
*/


/**
* Function docblock
*/
function correctSpacing($x) {}


/**
* Superfluous docblock
*/
/**
* Function docblock
*/
function incorrectSpacing($x) {}


}
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,29 @@ class SilenceBeforeErrorIfPreviousThingWasAFunctionBug


}//end class

// Issue #945.
class OnlyAcceptFirstDocblockAsBelongingWithFunction {
/**
* Superfluous docblock
*/


/**
* Function docblock
*/
function correctSpacing($x) {}


/**
* Superfluous docblock
*/


/**
* Function docblock
*/
function incorrectSpacing($x) {}


}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function getErrorList($testFile='')
714 => 1,
717 => 1,
727 => 1,
749 => 1,
];

case 'FunctionSpacingUnitTest.2.inc':
Expand Down