Skip to content

Commit

Permalink
support colon after date
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 14, 2023
1 parent a1b9d67 commit 9188ee4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/TodoByRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
final class TodoByRule implements Rule
{
private const PATTERN = '/^TODO:?\s*([0-9]{4}-[0-9]{2}-[0-9]{2})(.*)$/';
private const PATTERN = '/^TODO:?\s*([0-9]{4}-[0-9]{2}-[0-9]{2}):?(.*)$/';

public function getNodeType(): string
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scop
if ($todoText === '') {
$errorMessage = 'comment expired on '. $date .'.';
} else {
$errorMessage = "'$todoText' expired on ". $date .'.';
$errorMessage = "comment '$todoText' expired on ". $date .'.';
}

$errors[] = RuleErrorBuilder::message($errorMessage)->line($comment->getStartLine())->build();
Expand Down
18 changes: 9 additions & 9 deletions tests/TodoByRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@ public function testRule(): void
{
$this->analyse([__DIR__ . '/data/example.php'], [
[
"'Expired comment1' expired on 2023-12-14.",
"comment 'Expired comment1' expired on 2023-12-14.",
9,
],
[
"'Expired comment2' expired on 2023-12-14.",
"comment 'Expired comment2' expired on 2023-12-14.",
10,
],
[
"'Expired comment3' expired on 2023-12-14.",
"comment 'Expired comment3' expired on 2023-12-14.",
11,
],
[
"'Expired comment4' expired on 2023-12-14.",
"comment 'Expired comment4' expired on 2023-12-14.",
12,
],
[
"'Expired comment5' expired on 2023-12-14.",
"comment 'Expired comment5' expired on 2023-12-14.",
13,
],
[
"'Expired commentX' expired on 2023-12-14.",
"comment 'Expired commentX' expired on 2023-12-14.",
19,
],
[
"comment expired on 2023-12-14.",
21,
],
[
"'method comment' expired on 2023-12-14.",
"comment 'method comment' expired on 2023-12-14.",
27,
],
[
"'in method comment1' expired on 2023-12-14.",
"comment 'in method comment1' expired on 2023-12-14.",
29,
],
[
"'in method comment2' expired on 2023-12-14.",
"comment 'in method comment2' expired on 2023-12-14.",
31,
],
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/data/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Z {
public function XY():void {
// TODO: 2023-12-14 in method comment1
$x = 1;
// TODO: 2023-12-14 in method comment2
// TODO 2023-12-14: in method comment2
}
}

0 comments on commit 9188ee4

Please sign in to comment.