Skip to content

Commit

Permalink
Squiz/BlockComment: don't require a blank line between PHP open tag a…
Browse files Browse the repository at this point in the history
…nd block comment

Just like with scope openers, if a block comment is the first thing after a PHP open tag, no blank line should be required.

Includes unit tests.
  • Loading branch information
jrfnl committed Jan 4, 2019
1 parent 390bffe commit 134134e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ public function process(File $phpcsFile, $stackPtr)

// Check that the lines before and after this comment are blank.
$contentBefore = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if (isset($tokens[$contentBefore]['scope_closer']) === true
&& $tokens[$contentBefore]['scope_opener'] === $contentBefore
if ((isset($tokens[$contentBefore]['scope_closer']) === true
&& $tokens[$contentBefore]['scope_opener'] === $contentBefore)
|| $tokens[$contentBefore]['code'] === T_OPEN_TAG
) {
if (($tokens[$stackPtr]['line'] - $tokens[$contentBefore]['line']) !== 1) {
$error = 'Empty line not required before block comment';
Expand Down
14 changes: 14 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,17 @@ $y = 10 + /* test */ -2;
* See: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1918}
* @phpcs:disable Standard.Category.Sniff
*/

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

?>
<?php


/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,17 @@ $y = 10 + /* test */ -2;
* See: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1918}
* @phpcs:disable Standard.Category.Sniff
*/

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

?>
<?php


/*
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
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 @@ -41,6 +41,7 @@ public function setCliValues($testFile, $config)
public function getErrorList()
{
$errors = [
3 => 1,
8 => 1,
20 => 1,
24 => 1,
Expand Down Expand Up @@ -75,6 +76,7 @@ public function getErrorList()
227 => 1,
232 => 1,
233 => 1,
256 => 1,
];

return $errors;
Expand Down

0 comments on commit 134134e

Please sign in to comment.