Skip to content

Commit

Permalink
Ruleset tests: update for WPCS 3.0
Browse files Browse the repository at this point in the history
The ruleset tests were failing mainly due to WordPress/WordPress-Coding-Standards#2108 which renamed some violation codes that we were excluding.

The other change to account for was the replacement of a WPCS StrictComparisons sniff with a PHPCSExtras Universal sniff. The sniff in PHPCSExtra contains a fixer. As this is a risky fixer, this fixer is turned off for WPCS. The sniff in PHPCSExtra will provide metrics about loose versus strict comparisons.
  • Loading branch information
GaryJones committed Jun 20, 2023
1 parent d1e3f4f commit ed11da9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions WordPress-VIP-Go/ruleset-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ rawurlencode(); // Ok.
extract( array( 'a' => 1 ) ); // Error.
$obj->extract(); // Ok.

// WordPress.PHP.StrictComparisons.LooseComparison
// Universal.Operators.StrictComparisons.LooseComparison
true == $true; // Warning.
false === $true; // Ok.

Expand Down Expand Up @@ -546,7 +546,7 @@ str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error.

// WordPressVIPMinimum.Security.Underscorejs
echo "<script>
_.templateSettings = {
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g" . // Warning.
"};
</script>";
Expand Down
8 changes: 4 additions & 4 deletions WordPress-VIP-Go/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
This includes potential security holes as well as functions that may bring down sites for performance reasons.
-->
<!-- Should fix all of them but it doesn't need a manual review -->
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_fopen">
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fopen">
<message>File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as %s(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/</message>
</rule>
<rule ref="WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown">
Expand Down Expand Up @@ -193,7 +193,7 @@
<rule ref="WordPress.PHP.DontExtract">
<severity>3</severity>
</rule>
<rule ref="WordPress.PHP.StrictComparisons.LooseComparison">
<rule ref="Universal.Operators.StrictComparisons.LooseComparison">
<severity>3</severity>
</rule>
<rule ref="WordPress.PHP.StrictInArray.MissingTrueStrict">
Expand Down Expand Up @@ -263,10 +263,10 @@
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_readfile">
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_readfile">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_fclose">
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fclose">
<severity>0</severity>
</rule>

Expand Down
4 changes: 2 additions & 2 deletions WordPressVIPMinimum/ruleset-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ new WP_Query( array(
// WordPress.WP.GlobalVariablesOverride
$GLOBALS['wpdb'] = 'test'; // Error.

// WordPress.PHP.StrictComparisons
// Universal.Operators.StrictComparisons
if ( true == $true ) { // Warning.
}

Expand Down Expand Up @@ -555,7 +555,7 @@ str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error.

// WordPressVIPMinimum.Security.Underscorejs
echo "<script>
_.templateSettings = {
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g" . // Warning.
"};
</script>";
Expand Down
30 changes: 27 additions & 3 deletions WordPressVIPMinimum/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<rule ref="WordPress.DB.DirectDatabaseQuery"/>
<rule ref="WordPress.DB.SlowDBQuery"/>
<rule ref="WordPress.WP.GlobalVariablesOverride"/>
<rule ref="WordPress.PHP.StrictComparisons"/>
<rule ref="Universal.Operators.StrictComparisons" phpcs-only="true">
<type>warning</type>
</rule>
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition"/>
<rule ref="WordPress.PHP.StrictInArray"/>
<rule ref="WordPress.PHP.DontExtract"/>
Expand Down Expand Up @@ -123,9 +125,31 @@
<!-- This is already covered in WordPressVIPMinimum.Functions.StripTags.StripTagsOneParameter -->
<exclude name="WordPress.WP.AlternativeFunctions.strip_tags_strip_tags"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fwrite"/>
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_fwrite"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents"/>
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fputs -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_fputs"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_is_writable"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writeable -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_is_writeable"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_touch -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_touch"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.directory_mkdir -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_mkdir"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.directory_rmdir -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_rmdir"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.chmod_chgrp -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_chgrp"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.chmod_chmod -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_chmod"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.chmod_chown -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_chown"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename -->
<exclude name="WordPress.WP.AlternativeFunctions.rename_rename"/>
<!-- This is already covered in WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink -->
<exclude name="WordPress.WP.AlternativeFunctions.unlink_unlink"/>
</rule>
<!-- VIP recommends other functions -->
<rule ref="WordPress.WP.AlternativeFunctions.curl_curl_init">
Expand Down

0 comments on commit ed11da9

Please sign in to comment.