Skip to content
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

Auto-fix PEAR.Commenting.FunctionComment.SpacingAfter #3908

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
20 changes: 17 additions & 3 deletions src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,25 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
) {
$error = 'There must be no blank lines after the function comment';
$phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter');

if ($fix === true) {
$phpcsFile->fixer->beginChangeset();

while ($i < $stackPtr
&& $tokens[$i]['code'] === T_WHITESPACE
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
) {
$phpcsFile->fixer->replaceToken($i++, '');
}

$phpcsFile->fixer->endChangeset();
}

break;
}
}
}
}//end for
}//end if

$commentStart = $tokens[$commentEnd]['comment_opener'];
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
Expand Down
34 changes: 34 additions & 0 deletions src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,37 @@ class Something implements JsonSerializable {

public function blankLineDetectionC() {}
}

class SpacingAfter {
/**
* There are multiple blank lines between this comment and the next function.
*
* @return void
*/








public function multipleBlankLines() {}

/**
* There are multiple blank lines, and some "empty" lines with only
* spaces/tabs between this comment and the next function.
*
* @return void
*/









public function multipleLinesSomeEmpty() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ class Something implements JsonSerializable {
*
* @return mixed
*/

#[ReturnTypeWillChange]
public function blankLineDetectionA() {}

Expand All @@ -463,16 +462,30 @@ class Something implements JsonSerializable {
* @return mixed
*/
#[ReturnTypeWillChange]

public function blankLineDetectionB() {}

/**
* Blank line between both docblock and attribute and attribute and function declaration.
*
* @return mixed
*/

#[ReturnTypeWillChange]

public function blankLineDetectionC() {}
}

class SpacingAfter {
/**
* There are multiple blank lines between this comment and the next function.
*
* @return void
*/
public function multipleBlankLines() {}

/**
* There are multiple blank lines, and some "empty" lines with only
* spaces/tabs between this comment and the next function.
*
* @return void
*/
public function multipleLinesSomeEmpty() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function getErrorList()
455 => 1,
464 => 1,
473 => 1,
485 => 1,
501 => 1,
];

}//end getErrorList()
Expand Down
Loading