From 428845beb88f5e066eb5e464009d391f21d4331a Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sun, 6 Oct 2024 13:42:59 +0200 Subject: [PATCH 01/14] start libraries core --- .../Plugin_Repo/Libraries_Files_Check.php | 88 +++++++++++ .../CodeAnalysis/LibrariesCoreSniff.php | 141 ++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php create mode 100644 phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php diff --git a/includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php b/includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php new file mode 100644 index 000000000..040d84efb --- /dev/null +++ b/includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php @@ -0,0 +1,88 @@ + 'php', + 'standard' => 'PluginCheck', + 'sniffs' => 'PluginCheck.CodeAnalysis.LibrariesCore', + ); + } + + /** + * Gets the description for the check. + * + * Every check must have a short description explaining what the check does. + * + * @since 1.2.0. + * + * @return string Description. + */ + public function get_description(): string { + return __( 'Prevents using remote services that are not necessary.', 'plugin-check' ); + } + + /** + * Gets the documentation URL for the check. + * + * Every check must have a URL with further information about the check. + * + * @since 1.2.0. + * + * @return string The documentation URL. + */ + public function get_documentation_url(): string { + return __( 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#calling-files-remotely', 'plugin-check' ); + } +} diff --git a/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php b/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php new file mode 100644 index 000000000..5d52b653a --- /dev/null +++ b/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php @@ -0,0 +1,141 @@ +tokens[ $stackPtr ]['content']; + + if ( \T_INLINE_HTML !== $this->tokens[ $stackPtr ]['code'] ) { + try { + $end_ptr = TextStrings::getEndOfCompleteTextString( $this->phpcsFile, $stackPtr ); + $content = TextStrings::getCompleteTextString( $this->phpcsFile, $stackPtr ); + } catch ( RuntimeException $e ) { + // Parse error/live coding. + return; + } + } + + if ( empty( trim( $content ) ) ) { + return; + } + + // Known LibrariesCore services. + $look_known_LibrariesCore_services = array( + '/(? 0 ) { + foreach ( $matches[0] as $match ) { + $this->phpcsFile->addError( + 'LibrariesCore images, js, css, and other scripts to your servers or any remote service is disallowed.', + $this->find_token_in_multiline_string( $stackPtr, $content, $match[1] ), + 'LibrariesCore' + ); + } + } + + return ( $end_ptr + 1 ); + } + + /** + * Find the exact token on which the error should be reported for multi-line strings. + * + * @param int $stackPtr The position of the current token in the stack. + * @param string $content The complete, potentially multi-line, text string. + * @param int $match_offset The offset within the content at which the match was found. + * + * @return int The stack pointer to the token containing the start of the match. + */ + private function find_token_in_multiline_string( $stackPtr, $content, $match_offset ) { + $newline_count = 0; + if ( $match_offset > 0 ) { + $newline_count = substr_count( $content, "\n", 0, $match_offset ); + } + + // Account for heredoc/nowdoc text starting at the token *after* the opener. + if ( isset( Tokens::$heredocTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === true ) { + ++$newline_count; + } + + return ( $stackPtr + $newline_count ); + } +} From 5ce4e2167d7702ab1333524d55c8222e8a4f1995 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 11 Oct 2024 18:24:00 +0200 Subject: [PATCH 02/14] starting --- .../{Libraries_Files_Check.php => Libraries_Core_Check.php} | 2 +- includes/Checker/Default_Check_Repository.php | 1 + phpcs-sniffs/PluginCheck/ruleset.xml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) rename includes/Checker/Checks/Plugin_Repo/{Libraries_Files_Check.php => Libraries_Core_Check.php} (96%) diff --git a/includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php b/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php similarity index 96% rename from includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php rename to includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php index 040d84efb..4758a3ed8 100644 --- a/includes/Checker/Checks/Plugin_Repo/Libraries_Files_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php @@ -18,7 +18,7 @@ * * @since 1.2.0. */ -class Libraries_Check extends Abstract_PHP_CodeSniffer_Check { +class Libraries_Core_Check extends Abstract_PHP_CodeSniffer_Check { use Amend_Check_Result; use Stable_Check; diff --git a/includes/Checker/Default_Check_Repository.php b/includes/Checker/Default_Check_Repository.php index 7552ae948..524b21f97 100644 --- a/includes/Checker/Default_Check_Repository.php +++ b/includes/Checker/Default_Check_Repository.php @@ -60,6 +60,7 @@ private function register_default_checks() { 'trademarks' => new Checks\Plugin_Repo\Trademarks_Check(), 'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(), 'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(), + 'libraries_core' => new Checks\Plugin_Repo\Libraries_Core_Check(), ) ); diff --git a/phpcs-sniffs/PluginCheck/ruleset.xml b/phpcs-sniffs/PluginCheck/ruleset.xml index 655631218..c652f7dd0 100644 --- a/phpcs-sniffs/PluginCheck/ruleset.xml +++ b/phpcs-sniffs/PluginCheck/ruleset.xml @@ -5,5 +5,6 @@ + From b99c2e8c58c8220d91216e67d3b6c313907187f6 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 11 Oct 2024 18:59:43 +0200 Subject: [PATCH 03/14] register --- .../PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php b/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php index 5d52b653a..a983655ce 100644 --- a/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php +++ b/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php @@ -31,10 +31,7 @@ final class LibrariesCoreSniff extends Sniff { * @return array */ public function register() { - $targets = Collections::textStringStartTokens(); - $targets[] = \T_INLINE_HTML; - - return $targets; + return [T_STRING, T_CONSTANT_ENCAPSED_STRING]; } /** From 1fbbf14478c75504c9da7494b2abd0bdd02b2fe1 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 24 Oct 2024 23:09:14 +0200 Subject: [PATCH 04/14] info --- includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php b/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php index 4758a3ed8..8aff63cb4 100644 --- a/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php @@ -70,7 +70,7 @@ protected function get_args( Check_Result $result ) { * @return string Description. */ public function get_description(): string { - return __( 'Prevents using remote services that are not necessary.', 'plugin-check' ); + return __( 'Prevents using libraries that are already in the WordPress core.', 'plugin-check' ); } /** @@ -83,6 +83,6 @@ public function get_description(): string { * @return string The documentation URL. */ public function get_documentation_url(): string { - return __( 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#calling-files-remotely', 'plugin-check' ); + return __( 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#including-libraries-already-in-core', 'plugin-check' ); } } From 1d9b902faf9d2b7d5d73e5ee0762ee44da9ea3c0 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 24 Oct 2024 23:42:12 +0200 Subject: [PATCH 05/14] revert sniff --- .../Plugin_Repo/Libraries_Core_Check.php | 88 ----------- includes/Checker/Default_Check_Repository.php | 1 - .../CodeAnalysis/LibrariesCoreSniff.php | 138 ------------------ phpcs-sniffs/PluginCheck/ruleset.xml | 1 - 4 files changed, 228 deletions(-) delete mode 100644 includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php delete mode 100644 phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php diff --git a/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php b/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php deleted file mode 100644 index 8aff63cb4..000000000 --- a/includes/Checker/Checks/Plugin_Repo/Libraries_Core_Check.php +++ /dev/null @@ -1,88 +0,0 @@ - 'php', - 'standard' => 'PluginCheck', - 'sniffs' => 'PluginCheck.CodeAnalysis.LibrariesCore', - ); - } - - /** - * Gets the description for the check. - * - * Every check must have a short description explaining what the check does. - * - * @since 1.2.0. - * - * @return string Description. - */ - public function get_description(): string { - return __( 'Prevents using libraries that are already in the WordPress core.', 'plugin-check' ); - } - - /** - * Gets the documentation URL for the check. - * - * Every check must have a URL with further information about the check. - * - * @since 1.2.0. - * - * @return string The documentation URL. - */ - public function get_documentation_url(): string { - return __( 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#including-libraries-already-in-core', 'plugin-check' ); - } -} diff --git a/includes/Checker/Default_Check_Repository.php b/includes/Checker/Default_Check_Repository.php index 0eb27d499..7b0421863 100644 --- a/includes/Checker/Default_Check_Repository.php +++ b/includes/Checker/Default_Check_Repository.php @@ -60,7 +60,6 @@ private function register_default_checks() { 'trademarks' => new Checks\Plugin_Repo\Trademarks_Check(), 'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(), 'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(), - 'libraries_core' => new Checks\Plugin_Repo\Libraries_Core_Check(), 'image_functions' => new Checks\Performance\Image_Functions_Check(), ) ); diff --git a/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php b/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php deleted file mode 100644 index a983655ce..000000000 --- a/phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/LibrariesCoreSniff.php +++ /dev/null @@ -1,138 +0,0 @@ -tokens[ $stackPtr ]['content']; - - if ( \T_INLINE_HTML !== $this->tokens[ $stackPtr ]['code'] ) { - try { - $end_ptr = TextStrings::getEndOfCompleteTextString( $this->phpcsFile, $stackPtr ); - $content = TextStrings::getCompleteTextString( $this->phpcsFile, $stackPtr ); - } catch ( RuntimeException $e ) { - // Parse error/live coding. - return; - } - } - - if ( empty( trim( $content ) ) ) { - return; - } - - // Known LibrariesCore services. - $look_known_LibrariesCore_services = array( - '/(? 0 ) { - foreach ( $matches[0] as $match ) { - $this->phpcsFile->addError( - 'LibrariesCore images, js, css, and other scripts to your servers or any remote service is disallowed.', - $this->find_token_in_multiline_string( $stackPtr, $content, $match[1] ), - 'LibrariesCore' - ); - } - } - - return ( $end_ptr + 1 ); - } - - /** - * Find the exact token on which the error should be reported for multi-line strings. - * - * @param int $stackPtr The position of the current token in the stack. - * @param string $content The complete, potentially multi-line, text string. - * @param int $match_offset The offset within the content at which the match was found. - * - * @return int The stack pointer to the token containing the start of the match. - */ - private function find_token_in_multiline_string( $stackPtr, $content, $match_offset ) { - $newline_count = 0; - if ( $match_offset > 0 ) { - $newline_count = substr_count( $content, "\n", 0, $match_offset ); - } - - // Account for heredoc/nowdoc text starting at the token *after* the opener. - if ( isset( Tokens::$heredocTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === true ) { - ++$newline_count; - } - - return ( $stackPtr + $newline_count ); - } -} diff --git a/phpcs-sniffs/PluginCheck/ruleset.xml b/phpcs-sniffs/PluginCheck/ruleset.xml index cf2b479ba..d1a7fecf4 100644 --- a/phpcs-sniffs/PluginCheck/ruleset.xml +++ b/phpcs-sniffs/PluginCheck/ruleset.xml @@ -5,7 +5,6 @@ - From da44cb6d9d4329bbbabfdf6541d1a97c4ea59056 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 24 Oct 2024 23:44:54 +0200 Subject: [PATCH 06/14] check files --- .../Checks/Plugin_Repo/File_Type_Check.php | 93 +++++++++++++++++-- 1 file changed, 85 insertions(+), 8 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 1ac6a06fd..321e17e80 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -24,13 +24,14 @@ class File_Type_Check extends Abstract_File_Check { use Amend_Check_Result; use Stable_Check; - const TYPE_COMPRESSED = 1; - const TYPE_PHAR = 2; - const TYPE_VCS = 4; - const TYPE_HIDDEN = 8; - const TYPE_APPLICATION = 16; - const TYPE_BADLY_NAMED = 32; - const TYPE_ALL = 63; // Same as all of the above with bitwise OR. + const TYPE_COMPRESSED = 1; + const TYPE_PHAR = 2; + const TYPE_VCS = 4; + const TYPE_HIDDEN = 8; + const TYPE_APPLICATION = 16; + const TYPE_BADLY_NAMED = 32; + const TYPE_LIBRARY_CORE = 64; + const TYPE_ALL = 127; // Same as all of the above with bitwise OR. /** * Bitwise flags to control check behavior. @@ -95,6 +96,9 @@ protected function check_files( Check_Result $result, array $files ) { // Check for badly named files. $this->look_for_badly_named_files( $result, $files ); } + if ( $this->flags & self::TYPE_LIBRARY_CORE ) { + $this->look_for_library_core_files( $result, $files ); + } } /** @@ -294,6 +298,79 @@ function ( $file ) use ( $plugin_path ) { } } + /** + * Looks for library core 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_library_core_files( Check_Result $result, array $files ) { + // Known libraries that are part of WordPress core. + // https://meta.trac.wordpress.org/browser/sites/trunk/api.wordpress.org/public_html/core/credits/wp-59.php#L739 + $look_known_LibrariesCore_services = array( + '(?plugin()->path(); + + $files = array_map( + function ( $file ) use ( $plugin_path ) { + return str_replace( $plugin_path, '', $file ); + }, + $files + ); + + foreach ( $files as $file ) { + if ( preg_match( $combined_pattern, $file ) ) { + $this->add_result_error_for_file( + $result, + __( 'Library files that are already in the WordPress core are not permitted.', 'plugin-check' ), + 'library_core_files', + $file, + 0, + 0, + '', + 8 + ); + } + } + } + /** * Gets the description for the check. * @@ -304,7 +381,7 @@ function ( $file ) use ( $plugin_path ) { * @return string Description. */ public function get_description(): string { - return __( 'Detects the usage of hidden and compressed files, VCS directories, application files and badly named files.', 'plugin-check' ); + return __( 'Detects the usage of hidden and compressed files, VCS directories, application files,badly named files and library core files.', 'plugin-check' ); } /** From 290b5cc376a47b99319532fe97e0700c5bf3e6ae Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 24 Oct 2024 23:52:25 +0200 Subject: [PATCH 07/14] tests for new check --- .../PHPMailer.php | 1 + .../load.php | 17 +++++++++++++++++ .../Checker/Checks/File_Type_Check_Tests.php | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/PHPMailer.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/load.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/PHPMailer.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/PHPMailer.php new file mode 100644 index 000000000..b3d9bbc7f --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/PHPMailer.php @@ -0,0 +1 @@ +assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0] ); $this->assertCount( 1, wp_list_filter( $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); } + + public function test_run_with_library_core_errors() { + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-library-core-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check = new File_Type_Check( File_Type_Check::TYPE_LIBRARY_CORE ); + $check->run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertNotEmpty( $errors ); + $this->assertEquals( 1, $check_result->get_error_count() ); + + // Check for core PHPMailer. + $this->assertArrayHasKey( 0, $errors['PHPMailer.php'] ); + $this->assertArrayHasKey( 0, $errors['PHPMailer.php'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['PHPMailer.php'][0][0], array( 'code' => 'library_core_files' ) ) ); + } } From bf1eb072e5dd0749b4beb417aeb13c329cb2a55e Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 24 Oct 2024 23:56:55 +0200 Subject: [PATCH 08/14] fix tests --- includes/Checker/Checks/Plugin_Repo/File_Type_Check.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 321e17e80..a46d1d54c 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -308,8 +308,8 @@ function ( $file ) use ( $plugin_path ) { */ protected function look_for_library_core_files( Check_Result $result, array $files ) { // Known libraries that are part of WordPress core. - // https://meta.trac.wordpress.org/browser/sites/trunk/api.wordpress.org/public_html/core/credits/wp-59.php#L739 - $look_known_LibrariesCore_services = array( + // https://meta.trac.wordpress.org/browser/sites/trunk/api.wordpress.org/public_html/core/credits/wp-59.php#L739 . + $look_known_libraries_core_services = array( '(?plugin()->path(); From af43f88356304dbc21974c681d4d5a8a6cf8b226 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sun, 27 Oct 2024 12:54:58 +0100 Subject: [PATCH 09/14] updated from feedback --- includes/Checker/Checks/Plugin_Repo/File_Type_Check.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index a46d1d54c..c701a19d6 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -301,7 +301,7 @@ function ( $file ) use ( $plugin_path ) { /** * Looks for library core files and amends the given result with an error if found. * - * @since 1.2.0 + * @since 1.3.0 * * @param Check_Result $result The check result to amend, including the plugin context to check. * @param array $files List of absolute file paths. @@ -317,7 +317,7 @@ protected function look_for_library_core_files( Check_Result $result, array $fil 'jquery.hoverintent(?!\/)', 'jquery.imgareaselect(?!\/)', 'jquery.hotkeys(?!\/)', - 'jquery.ba-serializeobject(?!\/)', // spellchecker:disable-line + 'jquery.ba-serializeobject(?!\/)', // spellchecker:disable-line. 'jquery.query-object(?!\/)', 'jquery.suggest(?!\/)', 'polyfill(\.min)?\.js(?!\/)', @@ -382,7 +382,7 @@ function ( $file ) use ( $plugin_path ) { * @return string Description. */ public function get_description(): string { - return __( 'Detects the usage of hidden and compressed files, VCS directories, application files,badly named files and library core files.', 'plugin-check' ); + return __( 'Detects the usage of hidden and compressed files, VCS directories, application files, badly named files and library core files.', 'plugin-check' ); } /** From 79a65b3236e0e780b281f8084defbe3dc3b034b4 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Mon, 28 Oct 2024 23:08:49 +0100 Subject: [PATCH 10/14] added jquery --- .../test-plugin-file-type-library-core-errors/jquery.js | 1 + .../phpunit/tests/Checker/Checks/File_Type_Check_Tests.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js new file mode 100644 index 000000000..9f5ada378 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js @@ -0,0 +1 @@ +// For testing purposes, this file is empty. \ No newline at end of file diff --git a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php index c6e39875c..2a10aa111 100644 --- a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php @@ -138,11 +138,16 @@ public function test_run_with_library_core_errors() { $errors = $check_result->get_errors(); $this->assertNotEmpty( $errors ); - $this->assertEquals( 1, $check_result->get_error_count() ); + $this->assertEquals( 2, $check_result->get_error_count() ); // Check for core PHPMailer. $this->assertArrayHasKey( 0, $errors['PHPMailer.php'] ); $this->assertArrayHasKey( 0, $errors['PHPMailer.php'][0] ); $this->assertCount( 1, wp_list_filter( $errors['PHPMailer.php'][0][0], array( 'code' => 'library_core_files' ) ) ); + + // Check for core jquery. + $this->assertArrayHasKey( 0, $errors['jquery.js'] ); + $this->assertArrayHasKey( 0, $errors['jquery.js'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['jquery.js'][0][0], array( 'code' => 'library_core_files' ) ) ); } } From 0cd8ff958727428043e76cdd789c0139c1815153 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Mon, 28 Oct 2024 23:13:31 +0100 Subject: [PATCH 11/14] js lint --- .../plugins/test-plugin-file-type-library-core-errors/jquery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js index 9f5ada378..d22803be9 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-library-core-errors/jquery.js @@ -1 +1 @@ -// For testing purposes, this file is empty. \ No newline at end of file +// For testing purposes, this file is empty. From 4edf28fe1f9a8d5aec320cd03fae3b68ac46c792 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 29 Oct 2024 12:45:29 +0545 Subject: [PATCH 12/14] Add typos config --- .typos.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .typos.toml diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 000000000..a46c4964e --- /dev/null +++ b/.typos.toml @@ -0,0 +1,4 @@ +[default] +extend-ignore-re = [ + "ba", +] From 834c0c968639d351f90d855659a51f48b4a653b4 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 29 Oct 2024 12:48:58 +0545 Subject: [PATCH 13/14] Exclude toml file from the distribution --- .distignore | 1 + .gitattributes | 1 + includes/Checker/Checks/Plugin_Repo/File_Type_Check.php | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.distignore b/.distignore index fd46e5ff4..bf53a98c1 100644 --- a/.distignore +++ b/.distignore @@ -21,6 +21,7 @@ tests .gitignore .nvmrc .phpunit.result.cache +.typos.toml .wp-env.json .wp-env.override.json behat.yml diff --git a/.gitattributes b/.gitattributes index 0a48594fe..1610ea0d9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,6 +13,7 @@ /.editorconfig export-ignore /.eslintrc.js export-ignore /.nvmrc export-ignore +/.typos.toml export-ignore /.wp-env.json export-ignore /composer.lock export-ignore /package.json export-ignore diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index c701a19d6..59cd9d47a 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -317,7 +317,7 @@ protected function look_for_library_core_files( Check_Result $result, array $fil 'jquery.hoverintent(?!\/)', 'jquery.imgareaselect(?!\/)', 'jquery.hotkeys(?!\/)', - 'jquery.ba-serializeobject(?!\/)', // spellchecker:disable-line. + 'jquery.ba-serializeobject(?!\/)', 'jquery.query-object(?!\/)', 'jquery.suggest(?!\/)', 'polyfill(\.min)?\.js(?!\/)', From ed12bcccda0c0048c5cbf74ae35398cbebab4bb7 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Mon, 4 Nov 2024 22:55:55 +0100 Subject: [PATCH 14/14] changes as suggested --- includes/Checker/Checks/Plugin_Repo/File_Type_Check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 59cd9d47a..9853d53c6 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -382,7 +382,7 @@ function ( $file ) use ( $plugin_path ) { * @return string Description. */ public function get_description(): string { - return __( 'Detects the usage of hidden and compressed files, VCS directories, application files, badly named files and library core files.', 'plugin-check' ); + return __( 'Detects the usage of hidden and compressed files, VCS directories, application files, badly named files and Library Core Files.', 'plugin-check' ); } /**