Skip to content

Commit

Permalink
Squiz/BlockComment: also check for short open echo tag
Browse files Browse the repository at this point in the history
Includes unit tests.
  • Loading branch information
jrfnl committed Apr 22, 2021
1 parent ae4f33b commit 93306f5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public function process(File $phpcsFile, $stackPtr)
if ((isset($tokens[$contentBefore]['scope_closer']) === true
&& $tokens[$contentBefore]['scope_opener'] === $contentBefore)
|| $tokens[$contentBefore]['code'] === T_OPEN_TAG
|| $tokens[$contentBefore]['code'] === T_OPEN_TAG_WITH_ECHO
) {
if (($tokens[$stackPtr]['line'] - $tokens[$contentBefore]['line']) !== 1) {
$error = 'Empty line not required before block comment';
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,19 @@ $y = 10 + /* test */ -2;
/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/

?>
<?=
/*
* No blank line required above the comment if it's the first non-empty token after a PHP open tag.
*/

$contentToEcho
?>
<?=


/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
$contentToEcho
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,19 @@ $y = 10 + /* test */ -2;
/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/

?>
<?=
/*
* No blank line required above the comment if it's the first non-empty token after a PHP open tag.
*/

$contentToEcho
?>
<?=


/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
$contentToEcho
2 changes: 2 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function getErrorList()
232 => 1,
233 => 1,
256 => 1,
271 => 1,
273 => 1,
];

return $errors;
Expand Down

0 comments on commit 93306f5

Please sign in to comment.