Skip to content

Commit

Permalink
Add separate error message for empty and invalid plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 24, 2024
1 parent 22f17f1 commit c0c91bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions includes/Checker/Checks/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,23 @@ protected function check_files( Check_Result $result, array $files ) {
* @param Parser $parser The Parser object.
*/
private function check_name( Check_Result $result, string $readme_file, Parser $parser ) {
if ( empty( $parser->name ) || isset( $parser->warnings['invalid_plugin_name_header'] ) ) {
if ( isset( $parser->warnings['invalid_plugin_name_header'] ) ) {
$message = sprintf(

Check warning on line 104 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L104

Added line #L104 was not covered by tests
/* translators: 1: 'Plugin Name' section title, 2: 'Plugin Name' */
__( 'We cannot find a plugin name in your readme. Plugin names look like: %1$s. Please change %2$s to reflect the actual name of your plugin.', 'plugin-check' ),
__( 'Plugin names look like: %1$s. Please change %2$s to reflect the actual name of your plugin.', 'plugin-check' ),
"'=== Plugin Name ==='",
"'Plugin Name'"
);

Check warning on line 109 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L106-L109

Added lines #L106 - L109 were not covered by tests

$this->add_result_error_for_file( $result, $message, 'invalid_plugin_name', $readme_file );

Check warning on line 111 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L111

Added line #L111 was not covered by tests
} elseif ( empty( $parser->name ) ) {
$message = sprintf(

Check warning on line 113 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L113

Added line #L113 was not covered by tests
/* translators: %s: Example plugin name header */
__( 'We cannot find a plugin name in your readme. Please update your readme with a valid plugin name header. Eg: %s', 'plugin-check' ),
"'=== Example Name ==='"
);

Check warning on line 117 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L115-L117

Added lines #L115 - L117 were not covered by tests

$this->add_result_error_for_file( $result, $message, 'empty_plugin_name', $readme_file );

Check warning on line 119 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L119

Added line #L119 was not covered by tests
}
}

Expand Down

0 comments on commit c0c91bf

Please sign in to comment.