Skip to content

Commit b76fe28

Browse files
authored
Merge pull request #30 from woocommerce/improve/hooksniff
Add validation for since tag version
2 parents 4576d54 + 27edbab commit b76fe28

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/WooCommerce/Sniffs/Commenting/CommentHooksSniff.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function process(File $phpcsFile, $stackPtr)
6868
}
6969

7070
if (true === $correctly_placed) {
71-
7271
if (\T_COMMENT === $tokens[ $previous_comment ]['code']) {
7372
$phpcsFile->addError(
7473
'A "hook" comment must be a "/**" style docblock comment.',
@@ -83,6 +82,17 @@ public function process(File $phpcsFile, $stackPtr)
8382
// Iterate through each comment to check for "@since" tag.
8483
foreach ($tokens[ $comment_start ]['comment_tags'] as $tag) {
8584
if ($tokens[$tag]['content'] === '@since') {
85+
// Check if there is a version after the @since tag.
86+
if (! preg_match('/\d+\.\d+\.?\d?/', $tokens[$tag+2]['content'])) {
87+
$phpcsFile->addError(
88+
'A "@since" tag was found but no version declared. Required format <x.x> or <x.x.x>',
89+
$stackPtr,
90+
'MissingSinceVersionComment'
91+
);
92+
93+
return;
94+
}
95+
8696
return;
8797
}
8898
}

0 commit comments

Comments
 (0)