Skip to content

Commit d6f9dc0

Browse files
committed
Core: warn against the use of loose comparisons
As per the proposal in 1624, this moves the sniffs which `warn` against the use of loose comparisons to the Core ruleset. Open actions: * [x] Adjust Core PHP handbook to mention this rule in the `Clever code` section (or wherever else it should go).
1 parent f04207c commit d6f9dc0

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

WordPress-Core/ruleset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@
392392
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
393393
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
394394

395+
<!-- Rule: Unless absolutely necessary, loose comparisons should not be used,
396+
as their behaviour can be misleading. -->
397+
<rule ref="WordPress.PHP.StrictComparisons"/>
398+
<rule ref="WordPress.PHP.StrictInArray"/>
399+
395400
<!-- Rule: Assignments must not be placed in placed in conditionals.
396401
Note: sniff is a duplicate of upstream. Can be removed once minimum PHPCS requirement has gone up.
397402
https://github.com/squizlabs/PHP_CodeSniffer/pull/1594

WordPress-Extra/ruleset.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,10 @@
103103
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/26 -->
104104
<rule ref="WordPress.WP.GlobalVariablesOverride"/>
105105

106-
<!-- Encourage the use of strict ( === and !== ) comparisons.
107-
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/242 -->
108-
<rule ref="WordPress.PHP.StrictComparisons"/>
109-
110106
<!-- Detect incorrect or risky use of the `ini_set()` function.
111107
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1447 -->
112108
<rule ref="WordPress.PHP.IniSet"/>
113109

114-
<!-- Check that in_array() and array_search() use strict comparisons.
115-
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/399
116-
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/503 -->
117-
<rule ref="WordPress.PHP.StrictInArray"/>
118-
119110
<!-- Check enqueue and register styles and scripts to have version and in_footer parameters explicitly set.
120111
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1146 -->
121112
<rule ref="WordPress.WP.EnqueuedResourceParameters"/>

0 commit comments

Comments
 (0)