phpstan-todo-by icon indicating copy to clipboard operation
phpstan-todo-by copied to clipboard

Comments inside if statements are not parsed

Open thomasvisma opened this issue 1 year ago • 4 comments

Hi there,

we are using your package to identify TODOs with expired dates. First of all, great package and thanks for making it!

Recently we added a //todo 2024-09-10 inside an if statement and realized (after the deadline) that this was not picked up.

Issue

Comments inside if statements are not parsed, therefore no rules are triggered.

Version

phpstan-todo-by 0.1.27

Example

if (
// @todo 2024-08-01 Do something important 
$someStatement
) {
...
}

If the comment is moved to on top of the if, it will be parsed:

// @todo 2024-08-01 Do something important 
if (
$someStatement
) {
...
}

thomasvisma avatar Sep 17 '24 12:09 thomasvisma

thanks for reporting. ATM we don't see all comments because of shortcommings on the phpstan end, see https://github.com/phpstan/phpstan/discussions/11701#discussioncomment-10660711

hopefully we can address it in the future

staabm avatar Sep 17 '24 13:09 staabm

Thanks for your quick reply, and also the comment you linked - very interesting. We wrote some custom rules that also return an empty array if no issues are found - I was not aware of the caching issue, thanks for pointing me to that!

Regarding the issue, luckily //todo comments inside if statements are very rare :) but let's hope improvements to the parsing will solve this issue at some point in the future

thomasvisma avatar Sep 17 '24 13:09 thomasvisma

We wrote some custom rules that also return an empty array if no issues are found - I was not aware of the caching issue, thanks for pointing me to that!

note: the issue was about Collector rules. I did not yet check whether regular PHPStan\Rules\Rule are also affected.

staabm avatar Sep 17 '24 14:09 staabm

to get a more robust experience, I am thinking whether we should have a TodoBy attribute in addition to the current phpdoc syntax.

a attribute would have the benefit that PHPStan can verify whether it was placed at a supported location and therefore you can't accidentally put the todo no a unsupported element.

staabm avatar Feb 15 '25 10:02 staabm