Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 9, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3771:

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 squizlabs/PHP_CodeSniffer#3769 (well, aside from tags without a description, but that can't be helped)

Suggested changelog entry

  • Generic/Todo-Fixme: performance improvement
  • Generic/Todo: improved handling of "todo" and "fixme" tags in docblocks

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/targetted.
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.
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.
@jrfnl jrfnl force-pushed the feature/3769-improve-todo-fixme-sniffs branch from 8b6cceb to 0f89212 Compare December 26, 2023 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic.Commenting.Todo.CommentFound sample not working
1 participant