From e602cdd339833784bda1c1a00fafc331e9ee686b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Apr 2019 18:40:50 +0200 Subject: [PATCH 1/4] Composer: use wp-cli-tests ^2.1 ... as that version contains the new WPCliCS PHPCS standard. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9351d6a64..4ad7580dd 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "wp-cli/db-command": "^1.3 || ^2", "wp-cli/entity-command": "^1.3 || ^2", "wp-cli/extension-command": "^1.2 || ^2", - "wp-cli/wp-cli-tests": "^2.0.7" + "wp-cli/wp-cli-tests": "^2.1" }, "config": { "process-timeout": 7200, From 6f0fe5b8f70e7972e3e94bb3b0c02234b25a97f2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Apr 2019 18:41:06 +0200 Subject: [PATCH 2/4] .gitignore/.distignore: ignore phpcs/phpunit config files * `.distignore`: no need to distribute the phpcs/phpunit config files. * `.gitignore`: Allow devs to overwrite config files for PHPUnit and PHPCS - The `.dist` files should be committed. However, for their personal use, devs can overrule those files with versions without `.dist`. Those personal versions should never be committed. As a side-note: for PHPCS, having a personal version while still using the original `.dist` file is made very easy, as you can just import the `.dist` file as a starting point, like so: ```xml ``` --- .distignore | 2 ++ .gitignore | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.distignore b/.distignore index b964b40c7..95b52fb02 100644 --- a/.distignore +++ b/.distignore @@ -6,6 +6,8 @@ .travis.yml behat.yml circle.yml +phpcs.xml.dist +phpunit.xml.dist bin/ features/ utils/ diff --git a/.gitignore b/.gitignore index ff4941991..bcf211b32 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ vendor/ *.tar.gz composer.lock *.log +phpunit.xml +phpcs.xml +.phpcs.xml From 63af5d06ff6cb0a121d684c6e625806984524f24 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Apr 2019 18:41:15 +0200 Subject: [PATCH 3/4] PHPCS: add a ruleset for this project The file is completely documented in-line. --- phpcs.xml.dist | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..789662bb0 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,86 @@ + + + Custom ruleset for WP-CLI language-command + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */src/WP_CLI/(CommandWithTranslation|LanguagePackUpgrader)\.php$ + + + + + */src/(Core|Plugin|Site_Switch|Theme)_Language_Command\.php$ + */src/Language_Namespace\.php$ + + + From 7433d7c067c5f1554530ca904fc9eddff1faf2ba Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Apr 2019 20:29:03 +0200 Subject: [PATCH 4/4] PHPCS: whitelist some code for select sniffs --- src/Core_Language_Command.php | 2 +- src/Plugin_Language_Command.php | 1 + src/WP_CLI/LanguagePackUpgrader.php | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 80b8c0f99..03033a982 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -311,7 +311,7 @@ public function uninstall( $args, $assoc_args ) { * * @subcommand update */ - public function update( $args, $assoc_args ) { + public function update( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found -- Overruling the documentation, so not useless ;-). parent::update( $args, $assoc_args ); } diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index 44e495d42..57d51e5cb 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -466,6 +466,7 @@ public function update( $args, $assoc_args ) { * @return array */ private function get_all_plugins() { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Using WP native hook. return apply_filters( 'all_plugins', get_plugins() ); } } diff --git a/src/WP_CLI/LanguagePackUpgrader.php b/src/WP_CLI/LanguagePackUpgrader.php index 6572b5371..c8e29346a 100644 --- a/src/WP_CLI/LanguagePackUpgrader.php +++ b/src/WP_CLI/LanguagePackUpgrader.php @@ -57,8 +57,12 @@ public function download_package( $package ) { * @param bool $reply Whether to bail without returning the package. Default is false. * @param string $package The package file name. * @param \WP_Upgrader $this The WP_Upgrader instance. + * + * @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Using WP native hook. */ $reply = apply_filters( 'upgrader_pre_download', false, $package, $this ); + // phpcs:enable + if ( false !== $reply ) { return $reply; }