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

Deprecate use of the WPCS native whitelist comments #1580

Merged
merged 4 commits into from
Dec 21, 2018

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 20, 2018

Sniff::has_whitelist_comment(): Deprecate use of the WPCS native whitelist comments (PHPCS 3.2.0)

The WPCS native whitelist comments were introduced for lack of the ability to selectively ignore one or more sniffs for a piece of code.

PHPCS 3.2.0 introduced native PHPCS annotations which allow for selective ignoring/disabling of sniffs and while those were originally a bit buggy, all known bugs have been fixed since, making the WPCS native whitelist comments redundant.

This commit deprecates the method within WPCS which is used to check for the WPCS native whitelist comments.

It also introduces a warning which will be thrown whenever a WPCS native whitelist comment is encountered to alert people to this change and encourage them to switch over to the PHPCS native annotations.

Notes:

  • No deprecation notice will be thrown when a WPCS whitelist comment is combined with a PHPCS native annotation, i.e. // phpcs:ignore WP.Security.EscapeOutput -- WPCS: XSS ok.
  • As a sniff may be triggered several times for different tokens, a light weight (static) cache variable has been introduced to prevent the deprecation notice being thrown more than once for each WPCS whitelist comment encountered.

The Sniff::has_whitelist_comment() method and all calls to it should be removed in WPCS 3.0.0.

  • References to the WPCS native whitelist comments need to be removed from the wiki and/or replaced with an upgrade guide.
  • Open an issue about removing the Sniff::has_whitelist_comment() method and calls to it in WPCS 3.0.0.
    Note: all unit tests testing that the WPCS native whitelist comments are being respected should also be removed at that time. Or alternatively, they can remain and it should be verified that the WPCS native whitelist comment makes no difference anymore.

Refs:

WPCS native PHPCS ruleset: ignore a whitelist deprecation notice

The deprecation notice in this case is actually a false positive, however as the WPCS native whitelisting is now deprecated, fixing that false positive is a moot point.

SlowDBQuery: remove the warning about the deprecated tax_query whitelist comment

As the whole WPCS whitelist comment system is now deprecated, a notice will be thrown about that comment already. No need to also throw one about the comment using an old whitelist comment.

Unit tests: account for the new WPCS whitelist comment deprecation notices

A number of unit test case files contain WPCS whitelist comments to test that those are correctly being respected.
As of now, a deprecation warning for use of the WPCS whitelist comments will be thrown on those lines, so we need to make sure that PHPCS expects those warnings.

…elist comments (PHPCS 3.2.0)

The WPCS native whitelist comments were introduced for lack of the ability to selectively ignore one or more sniffs for a piece of code.

PHPCS 3.2.0 introduced native PHPCS annotations which allow for selective ignoring/disabling of sniffs and while those were originally a bit buggy, all known bugs have been fixed since, making the WPCS native whitelist comments redundant.

This commit deprecates the method within WPCS which is used to check for the WPCS native whitelist comments.

It also introduces a warning which will be thrown whenever a WPCS native whitelist comment is encountered to alert people to this change and encourage them to switch over to the PHPCS native annotations.

Notes:
* No deprecation notice will be thrown when a WPCS whitelist comment is combined with a PHPCS native annotation, i.e. `// phpcs:ignore WP.Security.EscapeOutput -- WPCS: XSS ok.`
* As a sniff may be triggered several times for different tokens, a light weight (static) cache variable has been introduced to prevent the deprecation notice being thrown more than once for each WPCS whitelist comment encountered.

The `Sniff::has_whitelist_comment()` method and all calls to it should be removed in WPCS 3.0.0.

- [ ] References to the WPCS native whitelist comments need to be removed from the wiki and/or replaced with an upgrade guide.
- [ ] Open an issue about removing the `Sniff::has_whitelist_comment()` method and calls to it in WPCS 3.0.0.
    Note: all unit tests testing that the WPCS native whitelist comments are being respected should also be removed at that time. Or alternatively, they can remain and it should be verified that the WPCS native whitelist comment makes no difference anymore.

Refs:
* squizlabs/PHP_CodeSniffer 604
The deprecation notice in this case is actually a false positive, however as the WPCS native whitelisting is now deprecated, fixing that false positive is a moot point.
…elist comment

As the whole WPCS whitelist comment system is now deprecated, a notice will be thrown about that comment already. No need to also throw one about the comment using an old whitelist comment.
…tices

A number of unit test case files contain WPCS whitelist comments to test that those are correctly being respected.
As of now, a deprecation warning for use of the WPCS whitelist comments will be thrown on those lines, so we need to make sure that PHPCS expects those warnings.
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.

2 participants