Open davidsneighbour opened 1 year ago
@davidsneighbour I've just tested and confirmed this issue, however, if you look at the sniff, you will see that the %s
is only added when the sniff could figure out a "todo message" and if the Generic.Commenting.Todo
sniff is run over the same code sample without a custom message
, the "todo message" also doesn't show.
To me, this looks more like something which needs to be improved in the sniff itself.
Most notably - it looks like the sniff looks at all comments and checks if they start with @todo
and not specifically at comments marked with a @todo
tag, which is tokenized differently.
@davidsneighbour I've opened PR #3771 with some improvements for the Generic.Commenting.Todo
sniff. I believe this should largely fix your concern. Testing appreciated.
Note: when there is a "todo description", the error code for the sniff is different (and always was), so your ruleset would not work as-is, you'll need to update it to:
<!-- This error code is for when no description is found. -->
<rule ref="Generic.Commenting.Todo.CommentFound">
<message>Please review this TODO comment</message>
<severity>3</severity>
</rule>
<!-- This error code is used when a task description is found. -->
<rule ref="Generic.Commenting.Todo.TaskFound">
<message>Please review this TODO comment: %s</message>
<severity>3</severity>
</rule>
@jrfnl
The ruleset.xml
example on the "Annotated-Ruleset" wiki page should also be edited.
(https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset#the-annotated-sample-file)
Line 215-218
<rule ref="Generic.Commenting.Todo.CommentFound">
<message>Please review this TODO comment: %s</message>
<severity>3</severity>
</rule>
Should be:
<rule ref="Generic.Commenting.Todo.TaskFound">
<message>Please review this TODO comment: %s</message>
<severity>3</severity>
</rule>
And CommentFound
in the comment above the rule snippet should be TaskFound
.
@stevenfoncken Thanks for pointing that out. I've updated the wiki page now.
Describe the bug
I configured my
Generic.Commenting.Todo.CommentFound
setup according to the docs in the wiki..There is more in the config, but I left it out for readability (full config at the end).
I would expect the following to throw an error like
Please review this TODO comment: @todo find out if this maybe is better suited at another location
orPlease review this TODO comment: find out if this maybe is better suited at another location
. But it throws onlyPlease review this TODO comment:
. It's notable in VSCode and on the CLI that two spaces are there at the end, as if %s is returning empty at that point.Code sample
This happens with ANY
@todo comment
comment.Versions (please complete the following information):
Complete config: