Skip to content

Commit

Permalink
Auto-fix PEAR.Commenting.FunctionComment.SpacingAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Oct 30, 2023
1 parent 321d252 commit 92b0c99
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
16 changes: 13 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,21 @@ 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) {
while ($i < $stackPtr
&& $tokens[$i]['code'] === T_WHITESPACE
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
) {
$phpcsFile->fixer->replaceToken($i++, '');
}
}

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

0 comments on commit 92b0c99

Please sign in to comment.