diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/TodoCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/TodoCommentSniff.php index c804a87c..a5d4623b 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/TodoCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/TodoCommentSniff.php @@ -129,13 +129,12 @@ private function checkTodoFormat(File $phpcsFile, $stackPtr, string $comment) } $expression = '/(?x) # Set free-space mode to allow this commenting - ^(\/\/)? # At the start optionally match two forward slashes - \s* # then any amount of whitespace + ^(\/|\s)* # At the start optionally match any forward slashes and spaces (?i) # set case-insensitive mode (?=( # start a postive non-consuming look-ahead to find all possible todos - @+to(-|\s|)+do # if one or more @ allow space or - between the to and do + @+to(-|\s|)+do # if one or more @ allow spaces and - between the to and do | # or - to(-)*do # if no @ then only accept todo or to-do or to--do, etc + to(-)*do # if no @ then only accept todo or to-do or to--do, etc, no spaces )) (?-i) # Reset to case-sensitive (?! # Start another non-consuming look-ahead, this time negative diff --git a/tests/Drupal/Commenting/TodoCommentUnitTest.inc b/tests/Drupal/Commenting/TodoCommentUnitTest.inc index fd06b1b5..0a4cdcc5 100644 --- a/tests/Drupal/Commenting/TodoCommentUnitTest.inc +++ b/tests/Drupal/Commenting/TodoCommentUnitTest.inc @@ -15,20 +15,20 @@ * @TODo Error * @ToDO Error * @todo: Error + * @todo : Error * @to-do Error * @TO-DO Error * @To-Do Error * @TO do Error - * @to do Error - * @todo: Error - * @todo : Error + * @to do Error * @todo- Error * @todo - Error * @todoError + * @todo Error * todo Error * TODO Error * ToDo Error - * @todo Error + * to-do Error */ function foo() { @@ -38,24 +38,27 @@ function foo() { // @todo $can start with a $ // @todo \also with backslash + // This is not a todo tag. It is a general comment and we do not want + // to do the standards checking here. + // These are all incorrect. // @TODO Error // @ToDo Error // @TODo Error // @ToDO Error // @todo: Error + // @todo : Error // @to-do Error // @TO-DO Error // @To-Do Error // @TO do Error // @to do Error - // @todo: Error - // @todo : Error + // @todo Error // @todo- Error // @todo - Error // @todoError // todo Error // TODO Error // ToDo Error - // @todo Error + // to-do Error } diff --git a/tests/Drupal/Commenting/TodoCommentUnitTest.php b/tests/Drupal/Commenting/TodoCommentUnitTest.php index f315a283..85ff1d4f 100644 --- a/tests/Drupal/Commenting/TodoCommentUnitTest.php +++ b/tests/Drupal/Commenting/TodoCommentUnitTest.php @@ -20,7 +20,7 @@ class TodoCommentUnitTest extends CoderSniffUnitTest */ protected function getErrorList(string $testFile): array { - $errorList = (array_fill_keys(range(13, 31), 1) + array_fill_keys(range(42, 60), 1)); + $errorList = (array_fill_keys(range(13, 31), 1) + array_fill_keys(range(45, 63), 1)); return $errorList; }//end getErrorList()