Skip to content

Commit

Permalink
Merge pull request #844 from WordPress/i18n-raise-errors
Browse files Browse the repository at this point in the history
Update severity for i18n codes
  • Loading branch information
ernilambar authored Dec 26, 2024
2 parents d4ed882 + c1f622b commit 6edfb9d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions includes/Checker/Checks/General/I18n_Usage_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ protected function add_result_message_for_file( Check_Result $result, $error, $m
break;
}

// Update severity.
switch ( $code ) {
case 'WordPress.WP.I18n.InterpolatedVariableDomain':
case 'WordPress.WP.I18n.MissingArgText':
case 'WordPress.WP.I18n.NoEmptyStrings':
case 'WordPress.WP.I18n.NonSingularStringLiteralContext':
case 'WordPress.WP.I18n.NonSingularStringLiteralDomain':
case 'WordPress.WP.I18n.TooManyFunctionArgs':
$severity = 7;
break;

default:
break;
}

parent::add_result_message_for_file( $result, $error, $message, $code, $file, $line, $column, $docs, $severity );
}
}
50 changes: 50 additions & 0 deletions tests/behat/features/plugin-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,53 @@ Feature: Test that the WP-CLI command works.
"""
application_detected
"""

Scenario: Check for i18n severity
Given a WP install with the Plugin Check plugin
And a wp-content/plugins/foo-sample/foo-sample.php file:
"""
<?php
/**
* Plugin Name: Foo Sample
* Plugin URI: https://foo-sample.com
* Description: Custom plugin.
* Version: 0.1.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
esc_html_e( 'Hello world', "${var}" );
esc_html_e( domain: 'foo-sample' );
esc_html_e( '%s', 'foo-sample' );
echo esc_html_x( 'Hello world', $var, 'foo-sample' );
esc_html_e( 'Hello world', $var );
esc_html_e( 'Hello world', 'foo-sample', 'too-many-args' );
"""

When I run the WP-CLI command `plugin check foo-sample --checks=i18n_usage --fields=line,type,code,severity --format=csv`
Then STDOUT should contain:
"""
13,ERROR,WordPress.WP.I18n.InterpolatedVariableDomain,7
"""
And STDOUT should contain:
"""
14,ERROR,WordPress.WP.I18n.MissingArgText,7
"""
And STDOUT should contain:
"""
15,ERROR,WordPress.WP.I18n.NoEmptyStrings,7
"""
And STDOUT should contain:
"""
16,ERROR,WordPress.WP.I18n.NonSingularStringLiteralContext,7
"""
And STDOUT should contain:
"""
17,ERROR,WordPress.WP.I18n.NonSingularStringLiteralDomain,7
"""
And STDOUT should contain:
"""
18,ERROR,WordPress.WP.I18n.TooManyFunctionArgs,7
"""

0 comments on commit 6edfb9d

Please sign in to comment.