Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: add option to exclude directories #311

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct( Plugin_Context $plugin_context ) {
* : The plugin to check. Plugin name.
*
* [--checks=<checks>]
* : Only runs checks provided as an argument in comma-separated values, e.g. enqueued-scripts, escaping. Otherwise runs all checks.
* : Only runs checks provided as an argument in comma-separated values, e.g. i18n_usage, late_escaping. Otherwise runs all checks.
*
* [--format=<format>]
* : Format to display the results. Options are table, csv, and json. The default will be a table.
Expand All @@ -87,10 +87,14 @@ public function __construct( Plugin_Context $plugin_context ) {
* [--include-experimental]
* : Include experimental checks.
*
* [--exclude-directories=<directories>]
* : Additional directories to exclude from checks
* By default, `.git`, `vendor` and `node_modules` directories are excluded.
*
* ## EXAMPLES
*
* wp plugin check akismet
* wp plugin check akismet --checks=escaping
* wp plugin check akismet --checks=late_escaping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

* wp plugin check akismet --format=json
*
* @subcommand check
Expand Down Expand Up @@ -128,6 +132,15 @@ public function check( $args, $assoc_args ) {
// Create the categories array from CLI arguments.
$categories = isset( $options['categories'] ) ? wp_parse_list( $options['categories'] ) : array();

$excluded_directories = isset( $options['exclude-directories'] ) ? wp_parse_list( $options['exclude-directories'] ) : array();

add_filter(
'wp_plugin_check_ignore_directories',
static function ( $dirs ) use ( $excluded_directories ) {
return array_unique( array_merge( $dirs, $excluded_directories ) );
}
);

// Get the CLI Runner.
$runner = Plugin_Request_Utility::get_runner();

Expand Down