squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Generic/Todo-Fixme sniffs: improve handling of docblock tags and efficiency fix #3771

Closed jrfnl closed 11 months ago

jrfnl commented 1 year ago

Generic/Todo-Fixme: make the sniffs more selective

The sniffs as-they-were, would sniff all comment related tokens, including T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE etc.

Sniffing those tokens is redundant and makes the sniffs slower than is needed.

Fixed now by making the tokens being registered by the sniffs more selective/targeted.

Generic/Todo: improve handling of "todo" tags in docblocks

Until now, the sniff would only examine an individual comment token, while when a @todo tag is used in a docblock, the "task description" is normally in the next T_DOC_COMMENT_STRING token.

This commit fixes this and the sniff will now take docblock @todo tags into account.

Includes additional unit tests.

Generic/Fixme: improve handling of "fixme" tags in docblocks

Essentially the same fix as applied in the sister-commit for the Generic.Commenting.Todo sniff.

Until now, the sniff would only examine an individual comment token, while when a @fixme tag is used in a docblock, the "task description" is normally in the next T_DOC_COMMENT_STRING token.

This commit fixes this and the sniff will now take docblock @fixme tags into account.

Includes additional unit tests.

Fixes #3769 (well, aside from tags without a description, but that can't be helped)

jrfnl commented 11 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/53