Skip to content

Commit

Permalink
Extra: do not allow ambiguous conditions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Mar 4, 2024
1 parent 9d29ddc commit 69a411e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions WordPress-Extra/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
https://github.com/WordPress/WordPress-Coding-Standards/pull/809 -->
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/>

<!-- Do not allow ambiguous conditions.
https://github.com/WordPress/WordPress-Coding-Standards/issues/2429 -->
<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>

<!-- Check that functions use all parameters passed.
https://github.com/WordPress/WordPress-Coding-Standards/issues/1510 -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
Expand Down

0 comments on commit 69a411e

Please sign in to comment.