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

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

Draft
wants to merge 4 commits into
base: feature/188-deprecate-all-sniffs-removed-in-4.0
Choose a base branch
from

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

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.
... as the order in which the files are found is OS-dependent, which makes the order of the messages OS-dependent, which made the test unstable.

Fixed now.
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.

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