Skip to content

Commit

Permalink
Merge branch 'trunk' into 702-check-including-libraries-already-in-wp…
Browse files Browse the repository at this point in the history
…-core-including-jquery
  • Loading branch information
davidperezgar authored Oct 13, 2024
2 parents b99c2e8 + fdd8002 commit 5368454
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 311 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/behat-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v4.5.0
uses: codecov/codecov-action@v4.6.0
with:
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@893cfea3da0870ceb77096be8b5fe014720f3c32
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
with:
file: build/logs/*.xml
flags: unit
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@893cfea3da0870ceb77096be8b5fe014720f3c32
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
with:
file: build/logs/*.xml
flags: phpcs-sniffs
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

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

54 changes: 52 additions & 2 deletions includes/Checker/Checks/Plugin_Repo/File_Type_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class File_Type_Check extends Abstract_File_Check {
const TYPE_VCS = 4;
const TYPE_HIDDEN = 8;
const TYPE_APPLICATION = 16;
const TYPE_ALL = 31; // Same as all of the above with bitwise OR.
const TYPE_BADLY_NAMED = 32;
const TYPE_ALL = 63; // Same as all of the above with bitwise OR.

/**
* Bitwise flags to control check behavior.
Expand Down Expand Up @@ -90,6 +91,10 @@ protected function check_files( Check_Result $result, array $files ) {
if ( $this->flags & self::TYPE_APPLICATION ) {
$this->look_for_application_files( $result, $files );
}
if ( $this->flags & self::TYPE_BADLY_NAMED ) {
// Check for badly named files.
$this->look_for_badly_named_files( $result, $files );
}
}

/**
Expand Down Expand Up @@ -244,6 +249,51 @@ protected function look_for_application_files( Check_Result $result, array $file
}
}

/**
* Looks for application files and amends the given result with an error if found.
*
* @since 1.2.0
*
* @param Check_Result $result The check result to amend, including the plugin context to check.
* @param array $files List of absolute file paths.
*/
protected function look_for_badly_named_files( Check_Result $result, array $files ) {
$conflict_chars = '!@#$%^&*()+=[]{};:"\'<>,?/\\|`~';

$plugin_path = $result->plugin()->path();

$files = array_map(
function ( $file ) use ( $plugin_path ) {
return str_replace( $plugin_path, '', $file );
},
$files
);

foreach ( $files as $file ) {
$badly_name = false;
if ( preg_match( '/\s/', $file ) ) {
$badly_name = true;
}

if ( preg_match( '/[' . preg_quote( $conflict_chars, '/' ) . ']/', basename( $file ) ) ) {
$badly_name = true;
}

if ( $badly_name ) {
$this->add_result_error_for_file(
$result,
__( 'Badly named files are not permitted.', 'plugin-check' ),
'badly_named_files',
$file,
0,
0,
'',
8
);
}
}
}

/**
* Gets the description for the check.
*
Expand All @@ -254,7 +304,7 @@ protected function look_for_application_files( Check_Result $result, array $file
* @return string Description.
*/
public function get_description(): string {
return __( 'Detects the usage of hidden and compressed files, VCS directories, and application files.', 'plugin-check' );
return __( 'Detects the usage of hidden and compressed files, VCS directories, application files and badly named files.', 'plugin-check' );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private function check_license( Check_Result $result, string $readme_file, Parse
}

// Checks for a valid license in Plugin Header.
if ( ! empty( $plugin_license ) && ! preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat/im', $plugin_license ) ) {
if ( ! empty( $plugin_license ) && ! preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat|Apache/im', $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' ),
Expand Down Expand Up @@ -419,6 +419,7 @@ private function normalize_licenses( $license ) {
$license = str_replace( '-', '', $license );
$license = str_replace( 'GNU General Public License (GPL)', 'GPL', $license );
$license = str_replace( 'GNU General Public License', 'GPL', $license );
$license = str_replace( ' version ', 'v', $license );
$license = preg_replace( '/GPL\s*[-|\.]*\s*[v]?([0-9])(\.[0])?/i', 'GPL$1', $license, 1 );
$license = str_replace( '.', '', $license );

Expand Down
Loading

0 comments on commit 5368454

Please sign in to comment.