Skip to content

Ruleset: hard deprecate $supportedTokenizers set to CSS/JS only #894

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

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 18, 2025

Description

⚠️ This PR needs for PR #888 to be merged first. ⚠️


Support for the JS and CSS Tokenizers will be removed in PHPCS 4.0.

This was announced in squizlabs/PHP_CodeSniffer#2448 and has been formalized via a soft deprecation (documentation and changelog only) in the PHPCS 3.9.0 release (see #276).

This commit implements a deprecation notice to alert sniff maintainers and ruleset maintainers to sniffs which are exclusively aimed at CSS and/or JS files.

This deprecation notice will not be shown if the sniff is formally deprecated via an implementation of the DeprecatedSniff interface (to prevent duplicate notifications).

Refs:

Includes an update to two tests in the PopulateTokenListenersTest to make these use one of the newly introduced fixtures to make these tests less dependent on the actual sniffs in PHPCS.

Suggested changelog entry

Added deprecation notices (hard deprecation) for:

  • Sniffs which don't listen for PHP, like JS/CSS specific sniffs,, which will no longer be supported in PHPCS 4.0.

Related issues/external references

Fixes #740

@jrfnl jrfnl added this to the 3.x Last milestone Mar 18, 2025
src/Ruleset.php Outdated
@@ -1470,13 +1472,30 @@ public function populateTokenListeners()

$tokenizers = [];
$vars = get_class_vars($sniffClass);
if (isset($vars['supportedTokenizers']) === true) {
if (empty($vars['supportedTokenizers']) === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a deprecation not a feature removal, we shouldn't be changing the behaviour. With the isset() check, it looks like an empty array would mean that a sniff would never run, whereas now that we're checking for empty(), that empty array value gets rewritten to PHP (in the else clause here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I made the change to avoid a deprecation notice being thrown for the property being set to an empty array - which is not terribly useful, but not something problematic either. This is tested via the ListensForEmptySniff test case.

But you're right, this does change the behaviour, so maybe the deprecation notice should be wrapped in its own conditions, independently of the conditions registering the tokenizers for the sniff.

What do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've update the PR with the above. Let me know what you think.

@jrfnl jrfnl modified the milestones: 3.x Last, 3.13.0 Apr 13, 2025
@jrfnl jrfnl force-pushed the feature/188-deprecate-all-sniffs-removed-in-4.0 branch from 0304898 to dd7257e Compare April 14, 2025 08:43
Base automatically changed from feature/188-deprecate-all-sniffs-removed-in-4.0 to master April 14, 2025 09:23
Support for the JS and CSS Tokenizers will be removed in PHPCS 4.0.

This was announced in squizlabs/PHP_CodeSniffer 2448 and has been formalized via a soft deprecation (documentation and changelog only) in the PHPCS 3.9.0 release (see 276).

This commit implements a deprecation notice to alert sniff maintainers and ruleset maintainers to sniffs which are exclusively aimed at CSS and/or JS files.

This deprecation notice will not be shown if the sniff is formally deprecated via an implementation of the `DeprecatedSniff` interface (to prevent duplicate notifications).

Refs:
* https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.3.0

Fixes 740

Includes an update to two tests in the `PopulateTokenListenersTest` to make these use one of the newly introduced fixtures to make these tests less dependent on the actual sniffs in PHPCS.
@jrfnl jrfnl force-pushed the feature/740-ruleset-show-deprecation-sniffs-scanning-js-css-files branch from ba8ae35 to bf6c4b2 Compare April 14, 2025 09:30
@jrfnl
Copy link
Member Author

jrfnl commented Apr 14, 2025

Rebased without changes before merging.

@jrfnl jrfnl marked this pull request as ready for review April 14, 2025 09:30
@jrfnl jrfnl merged commit a6f000e into master Apr 14, 2025
63 checks passed
@jrfnl jrfnl deleted the feature/740-ruleset-show-deprecation-sniffs-scanning-js-css-files branch April 14, 2025 10:08
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.

Last 3.x minor | Hard deprecate sniffs setting the $supportedTokenizers property
2 participants