Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
236 stars 40 forks source link

3.0: support WordPressCS 3.0 #779

Closed jrfnl closed 1 year ago

jrfnl commented 1 year ago

Composer: update WordPressCS + PHPCS dependencies

WordPressCS 3.0.0 has been released and requires a minimum PHPCS version of 3.7.2.

This commit updates the WordPressCS and PHPCS dependencies and the documentation referring to those, in all the relevant places.

Includes:

Ref: https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/3.0.0

WPCS 3.0 | Revert previously applied work-arounds

These are no longer needed with WPCS 3.0.0.

Ref: #746

Security/EscapingVoidReturnFunctions: switch to using WPCS PrintingFunctionsTrait

Note: this does mean that the sniff will now also support a public customPrintingFunctions property which can be adjusted in a custom ruleset.

AbstractVariableRestrictionsSniff: use WPCS ContextHelper::is_in_isset_or_empty()

AbstractVariableRestrictionsSniff: use WPCS RulesetPropertyHelper::merge_custom_array()

AbstractArrayAssignmentRestrictions children: adjust for changes in received $val

The $val parameter received by the callback() method will no longer automatically have been stripped of quotes.

This adjusts the callback() methods of the sniff which extend the WPCS AbstractArrayAssignmentRestrictions sniff to take this into account.

VIPMinimum ruleset: replace strict comparison sniff

Includes adding PHPCSExtra to the composer.json configuration as that is now a direct dependency of VIPCS as VIPCS now uses one of its sniffs in the ruleset.

Fixes #603

VIPMinimum ruleset: replace assignment-in-condition sniff

... which has been split.

VIPMinimum ruleset: update excludes for the WP/AlternativeFunctions sniff

... to prevent introducing new duplicate error messages.

Update ruleset tests: account for new errors from WPCS

WordPressVIPMinimum RulesetTest: fix it

To be honest, I'm completely stumped. I can't, for the life of me, think of a reason why the update of the WPCS dependency would suddenly cause all sorts of notices from the VariableAnalysis to show, where they previously did not.

As things are, I'm out of ideas of why these warnings are now suddenly showing up, so all I can do is fix them (by selectively silencing the notices from VA).

Note: this is only happening in the Minimum ruleset test as VIPGo silences the UnusedVariable notice completely.

Closes #727 (as WPCS 3.0.0 will no longer throw deprecations on PHP 8.x)