Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ public function process(File $phpcsFile, $stackPtr)
}
}

if ($phpcsFile->tokenizerType === 'PHP'
&& preg_match('|^//[ \t]*@[^\s]+|', $tokens[$stackPtr]['content']) === 1
) {
$error = 'Annotations may not appear after statements';
$phpcsFile->addError($error, $stackPtr, 'AnnotationFound');
return;
}

$error = 'Comments may not appear after statements';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found');
if ($fix === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ $match = match($foo // comment
) {
1 => 1, // comment
};

// Comments recognized as annotations by PHPCS.
$a = 1; //@codeCoverageIgnore
$b = 2; // @phpstan-ignore variable.undefined
$c = 3; // @phpstan-ignore variable.undefined
$d = 4; // @tabInsteadOfSpace

// Comments that include `@`, but are not recognized as annotations by PHPCS.
$a = 1; // @ = add tag.
$b = 2; // Some comment. // @username
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ $match = match($foo // comment
1 => 1,
// comment
};

// Comments recognized as annotations by PHPCS.
$a = 1; //@codeCoverageIgnore
$b = 2; // @phpstan-ignore variable.undefined
$c = 3; // @phpstan-ignore variable.undefined
$d = 4; // @tabInsteadOfSpace

// Comments that include `@`, but are not recognized as annotations by PHPCS.
$a = 1;
// @ = add tag.
$b = 2;
// Some comment. // @username
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public function getErrorList($testFile='')
18 => 1,
35 => 1,
53 => 1,
57 => 1,
58 => 1,
59 => 1,
60 => 1,
63 => 1,
64 => 1,
];

case 'PostStatementCommentUnitTest.1.js':
Expand Down