Skip to content

Commit

Permalink
Add validation for since tag version
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Jun 27, 2022
1 parent 4576d54 commit 27edbab
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/WooCommerce/Sniffs/Commenting/CommentHooksSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function process(File $phpcsFile, $stackPtr)
}

if (true === $correctly_placed) {

if (\T_COMMENT === $tokens[ $previous_comment ]['code']) {
$phpcsFile->addError(
'A "hook" comment must be a "/**" style docblock comment.',
Expand All @@ -83,6 +82,17 @@ public function process(File $phpcsFile, $stackPtr)
// Iterate through each comment to check for "@since" tag.
foreach ($tokens[ $comment_start ]['comment_tags'] as $tag) {
if ($tokens[$tag]['content'] === '@since') {
// Check if there is a version after the @since tag.
if (! preg_match('/\d+\.\d+\.?\d?/', $tokens[$tag+2]['content'])) {
$phpcsFile->addError(
'A "@since" tag was found but no version declared. Required format <x.x> or <x.x.x>',
$stackPtr,
'MissingSinceVersionComment'
);

return;
}

return;
}
}
Expand Down

0 comments on commit 27edbab

Please sign in to comment.