Skip to content

Commit

Permalink
Merge pull request #836 from WordPress/830-exclude-in-ruleset-not-wor…
Browse files Browse the repository at this point in the history
…king-for-json_encode

Update exclude rule for WP alternative functions sniff
  • Loading branch information
ernilambar authored Dec 17, 2024
2 parents 288b5cc + c9d0d23 commit 1f446de
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion phpcs-rulesets/plugin-review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<!-- Check for code WP does better -->
<rule ref="WordPress.WP.AlternativeFunctions">
<type>error</type>
<exclude name="WordPress.WP.AlternativeFunctions.json_encode"/>
<exclude name="WordPress.WP.AlternativeFunctions.json_encode_json_encode"/>
</rule>

<rule ref="Generic.PHP.ForbiddenFunctions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@

parse_str( 'first=value&arr[]=foo+bar&arr[]=baz' );

$encoded_value = json_encode( array( 'key' => 'value' ) );

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function test_run_with_errors() {
// Check for PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing error on Line no 34 and column no at 1.
$this->assertSame( 'PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing', $errors['load.php'][34][1][0]['code'] );

// There should not be WordPress.WP.AlternativeFunctions.json_encode_json_encode error on Line no 36 and column no at 18.
$this->assertCount( 0, wp_list_filter( $errors['load.php'][36][18], array( 'code' => 'WordPress.WP.AlternativeFunctions.json_encode_json_encode' ) ) );

// Check for WordPress.Security.ValidatedSanitizedInput warnings on Line no 15 and column no at 27.
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.MissingUnslash' ) ) );
Expand Down

0 comments on commit 1f446de

Please sign in to comment.