Skip to content

Commit 009c701

Browse files
committed
Modify regex and add more tests based on PR review feedback
1 parent f6053a3 commit 009c701

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/Standards/Squiz/Sniffs/Commenting/PostStatementCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function process(File $phpcsFile, $stackPtr)
110110
}
111111

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

src/Standards/Squiz/Tests/Commenting/PostStatementCommentUnitTest.inc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ $match = match($foo // comment
5353
1 => 1, // comment
5454
};
5555

56-
$a = 1; // @codeCoverageIgnore
57-
$b = 2; //@phpstan-ignore variable.undefined
58-
$c = 3; // @thisIsNotAnAnnotation - more than one space before the @ symbol.
56+
// Comments recognized as annotations by PHPCS.
57+
$a = 1; //@codeCoverageIgnore
58+
$b = 2; // @phpstan-ignore variable.undefined
59+
$c = 3; // @phpstan-ignore variable.undefined
60+
$d = 4; // @tabInsteadOfSpace
61+
62+
// Comments that include `@`, but are not recognized as annotations by PHPCS.
63+
$a = 1; // @ = add tag.
64+
$b = 2; // Some comment. // @username

src/Standards/Squiz/Tests/Commenting/PostStatementCommentUnitTest.inc.fixed

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ $match = match($foo // comment
5858
// comment
5959
};
6060

61-
$a = 1; // @codeCoverageIgnore
62-
$b = 2; //@phpstan-ignore variable.undefined
63-
$c = 3;
64-
// @thisIsNotAnAnnotation - more than one space before the @ symbol.
61+
// Comments recognized as annotations by PHPCS.
62+
$a = 1; //@codeCoverageIgnore
63+
$b = 2; // @phpstan-ignore variable.undefined
64+
$c = 3; // @phpstan-ignore variable.undefined
65+
$d = 4; // @tabInsteadOfSpace
66+
67+
// Comments that include `@`, but are not recognized as annotations by PHPCS.
68+
$a = 1;
69+
// @ = add tag.
70+
$b = 2;
71+
// Some comment. // @username

src/Standards/Squiz/Tests/Commenting/PostStatementCommentUnitTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ public function getErrorList($testFile='')
4040
18 => 1,
4141
35 => 1,
4242
53 => 1,
43-
56 => 1,
4443
57 => 1,
4544
58 => 1,
45+
59 => 1,
46+
60 => 1,
47+
63 => 1,
48+
64 => 1,
4649
];
4750

4851
case 'PostStatementCommentUnitTest.1.js':

0 commit comments

Comments
 (0)