Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/745-slug-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar authored Nov 24, 2024
2 parents 16f8e09 + a297a3a commit f430cc2
Show file tree
Hide file tree
Showing 27 changed files with 436 additions and 200 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/behat-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
fail-fast: true
matrix:
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
Expand All @@ -70,7 +68,7 @@ jobs:
- php: '8.2'
wordpress: 'latest'
coverage: true
- php: '7.2'
- php: '7.4'
wordpress: '6.3'
- php: '8.3'
wordpress: 'trunk'
Expand Down Expand Up @@ -157,7 +155,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.2
with:
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ jobs:
fail-fast: true
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
wordpress: [ 'latest' ]
include:
- php: '7.2'
- php: '7.4'
wordpress: '6.3'
- php: '8.2'
wordpress: 'latest'
Expand Down Expand Up @@ -101,7 +100,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a
with:
file: build/logs/*.xml
flags: unit
Expand All @@ -115,8 +114,6 @@ jobs:
fail-fast: true
matrix:
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
Expand Down Expand Up @@ -149,7 +146,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a
with:
file: build/logs/*.xml
flags: phpcs-sniffs
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thank you for your interest in contributing to the Plugin Check plugin!
In general, all code must follow the [WordPress Coding Standards and best practices](https://developer.wordpress.org/coding-standards/). All code in the Plugin Check plugin must follow these requirements:

- **WordPress**: The plugin's minimum WordPress version requirement is 6.3.
- **PHP**: Always match the latest WordPress version. The minimum required version right now is 7.2.24.
- **PHP**: The minimum required version right now is 7.4.

## Guidelines

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "GPL-2.0-or-later",
"type": "wordpress-plugin",
"require": {
"php": ">=7.2.24",
"php": ">=7.4",
"ext-json": "*",
"afragen/wordpress-plugin-readme-parser": "dev-master#67fba498d0b112acf84386b95e4905c539a33f0b",
"automattic/vipwpcs": "^3.0.0",
Expand Down Expand Up @@ -56,7 +56,7 @@
"phpstan/extension-installer": true
},
"platform": {
"php": "7.2.24"
"php": "7.4"
}
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 45 additions & 28 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public function __construct( Plugin_Context $plugin_context ) {
* [--warning-severity=<warning-severity>]
* : Warning severity level.
*
* [--include-low-severity-errors]
* : Include errors with lower severity than the threshold as other type.
*
* [--include-low-severity-warnings]
* : Include warnings with lower severity than the threshold as other type.
*
* [--slug=<slug>]
* : Slug to override the default.
*
Expand Down Expand Up @@ -138,15 +144,17 @@ public function check( $args, $assoc_args ) {
$options = $this->get_options(
$assoc_args,
array(
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'slug' => '',
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'include-low-severity-errors' => false,
'include-low-severity-warnings' => false,
'slug' => '',
)
);

Expand Down Expand Up @@ -235,8 +243,10 @@ static function ( $dirs ) use ( $excluded_files ) {
$formatter = $this->get_formatter( $assoc_args, $default_fields );

// Severity.
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false;
$include_low_severity_warnings = ! empty( $options['include-low-severity-warnings'] ) ? true : false;

// Print the formatted results.
// Go over all files with errors first and print them, combined with any warnings in the same file.
Expand All @@ -249,7 +259,7 @@ static function ( $dirs ) use ( $excluded_files ) {
$file_results = $this->flatten_file_results( $file_errors, $file_warnings );

if ( '' !== $error_severity || '' !== $warning_severity ) {
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) );
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings );
}

if ( ! empty( $file_results ) ) {
Expand All @@ -262,7 +272,7 @@ static function ( $dirs ) use ( $excluded_files ) {
$file_results = $this->flatten_file_results( array(), $file_warnings );

if ( '' !== $error_severity || '' !== $warning_severity ) {
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) );
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings );
}

if ( ! empty( $file_results ) ) {
Expand Down Expand Up @@ -626,25 +636,32 @@ private function display_results( $formatter, $file_name, $file_results ) {
*
* @since 1.1.0
*
* @param array $results Check results.
* @param int $error_severity Error severity level.
* @param int $warning_severity Warning severity level.
* @param array $results Check results.
* @param int $error_severity Error severity level.
* @param int $warning_severity Warning severity level.
* @param bool $include_low_severity_errors Include less level of severity issues as warning.
* @param bool $include_low_severity_warnings Include less level of severity issues as warning.
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @return array Filtered results.
*/
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) {
$errors = array_filter(
$results,
function ( $item ) use ( $error_severity ) {
return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity );
}
);
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false, $include_low_severity_warnings = false ) {
$errors = array();
$warnings = array();

$warnings = array_filter(
$results,
function ( $item ) use ( $warning_severity ) {
return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity );
foreach ( $results as $item ) {
if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) {
$errors[] = $item;
} elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) {
$item['type'] = 'ERRORS_LOW_SEVERITY';
$errors[] = $item;
} elseif ( $include_low_severity_warnings && 'WARNING' === $item['type'] && $item['severity'] < $warning_severity ) {
$item['type'] = 'WARNINGS_LOW_SEVERITY';
$warnings[] = $item;
} elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) {
$warnings[] = $item;
}
);
}

return array_merge( $errors, $warnings );
}
Expand Down
25 changes: 25 additions & 0 deletions includes/Checker/Checks/General/I18n_Usage_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ protected function add_result_message_for_file( Check_Result $result, $error, $m
$error = false;
}

// Add documentation link.
switch ( $code ) {
case 'WordPress.WP.I18n.NonSingularStringLiteralDomain':
case 'WordPress.WP.I18n.NonSingularStringLiteralText':
case 'WordPress.WP.I18n.TooManyFunctionArgs':
$docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#basic-strings', 'plugin-check' );
break;

case 'WordPress.WP.I18n.NonSingularStringLiteralContext':
$docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#disambiguation-by-context', 'plugin-check' );
break;

case 'WordPress.WP.I18n.MissingTranslatorsComment':
$docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#descriptions', 'plugin-check' );
break;

case 'WordPress.WP.I18n.UnorderedPlaceholdersText':
$docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#variables', 'plugin-check' );
break;

default:
$docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/', 'plugin-check' );
break;
}

parent::add_result_message_for_file( $result, $error, $message, $code, $file, $line, $column, $docs, $severity );
}
}
40 changes: 40 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Static_Check;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\License_Utils;
use WordPress\Plugin_Check\Traits\Stable_Check;

/**
Expand All @@ -22,6 +23,7 @@
class Plugin_Header_Fields_Check implements Static_Check {

use Amend_Check_Result;
use License_Utils;
use Stable_Check;

/**
Expand Down Expand Up @@ -67,6 +69,8 @@ public function run( Check_Result $result ) {
'RequiresPHP' => 'Requires PHP',
'UpdateURI' => 'Update URI',
'RequiresPlugins' => 'Requires Plugins',
'License' => 'License',
'LicenseURI' => 'License URI',
);

$restricted_labels = array(
Expand Down Expand Up @@ -249,6 +253,42 @@ public function run( Check_Result $result ) {
}
}

if ( empty( $plugin_header['License'] ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: %s: plugin header field */
__( '<strong>Missing "%s" in Plugin Header.</strong><br>Please update your Plugin Header with a valid GPLv2 (or later) compatible license.', 'plugin-check' ),
esc_html( $labels['License'] )
),
'plugin_header_no_license',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared',
9
);
} else {
$plugin_license = $this->get_normalized_license( $plugin_header['License'] );
if ( ! $this->is_license_gpl_compatible( $plugin_license ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: 1: plugin header field, 2: license */
__( '<strong>Invalid %1$s: %2$s.</strong><br>Please update your Plugin Header with a valid GPLv2 (or later) compatible license.', 'plugin-check' ),
esc_html( $labels['License'] ),
esc_html( $plugin_header['License'] )
),
'plugin_header_invalid_license',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared',
9
);
}
}

$found_headers = array();

foreach ( $restricted_labels as $restricted_key => $restricted_label ) {
Expand Down
34 changes: 6 additions & 28 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private function check_license( Check_Result $result, string $readme_file, Parse

// Test for a valid SPDX license identifier.
if ( ! $this->is_license_valid_identifier( $license ) ) {
$this->add_result_warning_for_file(
$this->add_result_error_for_file(
$result,
__( '<strong>Your plugin has an invalid license declared.</strong><br>Please update your readme with a valid SPDX license identifier.', 'plugin-check' ),
'invalid_license',
Expand All @@ -338,40 +338,18 @@ private function check_license( Check_Result $result, string $readme_file, Parse
);
}

$plugin_license = '';

$pattern = preg_quote( 'License', '/' );
$has_license = self::file_preg_match( "/(*ANYCRLF)^.*$pattern\s*:\s*(.*)$/im", array( $plugin_main_file ), $matches_license );
if ( ! $has_license ) {
$this->add_result_error_for_file(
$result,
__( '<strong>Your plugin has no license declared in Plugin Header.</strong><br>Please update your plugin header with a GPLv2 (or later) compatible license. It is necessary to declare the license of this plugin. You can do this by using the fields available both in the plugin readme and in the plugin headers.', 'plugin-check' ),
'no_license',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared',
9
);
} else {
$plugin_license = $this->get_normalized_license( $matches_license[1] );
}

// Checks for a valid license in Plugin Header.
if ( ! empty( $plugin_license ) && ! $this->is_license_gpl_compatible( $plugin_license ) ) {
$this->add_result_error_for_file(
$result,
__( '<strong>Your plugin has an invalid license declared in Plugin Header.</strong><br>Please update your readme with a valid GPL license identifier. It is necessary to declare the license of this plugin. You can do this by using the fields available both in the plugin readme and in the plugin headers.', 'plugin-check' ),
'invalid_license',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared',
9
);
if ( $has_license ) {
$plugin_license = $this->get_normalized_license( $matches_license[1] );
}

// Check different license types.
if ( ! empty( $plugin_license ) && ! empty( $license ) && $license !== $plugin_license ) {
$this->add_result_warning_for_file(
$this->add_result_error_for_file(
$result,
__( '<strong>Your plugin has a different license declared in the readme file and plugin header.</strong><br>Please update your readme with a valid GPL license identifier.', 'plugin-check' ),
'license_mismatch',
Expand Down
Loading

0 comments on commit f430cc2

Please sign in to comment.