From 9d29ddce34c0dc034d12073488b640243e07bd6a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 16 Feb 2024 14:30:09 +0100 Subject: [PATCH 1/2] Composer: raise the minimum supported PHPCS version to 3.9.0 --- .github/CONTRIBUTING.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 06f9b9065..4904cd9e7 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -39,7 +39,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class ## Pre-requisites * WordPress-Coding-Standards -* PHP_CodeSniffer 3.8.0 or higher +* PHP_CodeSniffer 3.9.0 or higher * PHPCSUtils 1.0.9 or higher * PHPCSExtra 1.2.1 or higher * PHPUnit 4.x - 9.x diff --git a/composer.json b/composer.json index f54f51332..2a41cd4c5 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "ext-libxml": "*", "ext-tokenizer": "*", "ext-xmlreader": "*", - "squizlabs/php_codesniffer": "^3.8.0", + "squizlabs/php_codesniffer": "^3.9.0", "phpcsstandards/phpcsutils": "^1.0.9", "phpcsstandards/phpcsextra": "^1.2.1" }, From 92751a146a1bf179441618ebff198d2eb6b2aa22 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 16 Feb 2024 14:35:21 +0100 Subject: [PATCH 2/2] Extra: do not allow ambiguous conditions This new PHPCS 3.9.0 sniff will flag code which contains a `||` and a `&&` operator in the same condition and their precedence is not clarified via parenthesis. This should allow for users of WPCS to find/prevent some bugs in code. I'd personally would **_highly_** recommend for WP Core to also use this sniff, but I suspect that will need due discussion/Make post/handbook change. Note: running this sniff on WP Core as-is, would (to my surprise) not actually trigger any new errors. Includes updating a code snippet in the Ruleset test to comply. --- Tests/RulesetCheck/class-ruleset-test.inc | 2 +- WordPress-Extra/ruleset.xml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/RulesetCheck/class-ruleset-test.inc b/Tests/RulesetCheck/class-ruleset-test.inc index b674946de..e45a2bc7d 100644 --- a/Tests/RulesetCheck/class-ruleset-test.inc +++ b/Tests/RulesetCheck/class-ruleset-test.inc @@ -64,7 +64,7 @@ class Ruleset_Test { if ( preg_match( '`' . preg_quote( $param_a, '`' ) . '`i', $param_b ) === 1 ) { echo esc_html( "doublequoted $string" ); } elseif ( $this->a ) { - $ab = $a % $b + $c / $d && $param_a || $param_b >> $bitshift; + $ab = $a % $b + $c / $d && ( $param_a || $param_b >> $bitshift ); } }; diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 8b065c7a1..ab0e8db3b 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -41,6 +41,10 @@ https://github.com/WordPress/WordPress-Coding-Standards/pull/809 --> + + +