Skip to content

Commit

Permalink
Merge branch 'php-8.0/squiz-inlinecomment-support-attributes' of http…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jul 28, 2021
2 parents 6c0437b + 82c9d12 commit 0108d40
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ public function process(File $phpcsFile, $stackPtr)
// We are only interested in inline doc block comments, which are
// not allowed.
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$nextToken = $phpcsFile->findNext(
Tokens::$emptyTokens,
($stackPtr + 1),
null,
true
);
$nextToken = $stackPtr;
do {
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextToken + 1), null, true);
if ($tokens[$nextToken]['code'] === T_ATTRIBUTE) {
$nextToken = $tokens[$nextToken]['attribute_closer'];
continue;
}

break;
} while (true);

$ignore = [
T_CLASS,
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ if ($foo) {
// another comment here.
$foo++;

/**
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
*/

#[AttributeA]

final class MyClass
{
/**
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
*/
#[AttributeA]
#[AttributeB]
final public function test() {}
}

/*
* N.B.: The below test line must be the last test in the file.
* Testing that a new line after an inline comment when it's the last non-whitespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ if ($foo) {
// another comment here.
$foo++;

/**
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
*/

#[AttributeA]

final class MyClass
{
/**
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
*/
#[AttributeA]
#[AttributeB]
final public function test() {}
}

/*
* N.B.: The below test line must be the last test in the file.
* Testing that a new line after an inline comment when it's the last non-whitespace
Expand Down

0 comments on commit 0108d40

Please sign in to comment.