From 1e581ba095e5f7715ed21d8f6df38d6aeae15380 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 08:53:58 -0400 Subject: [PATCH 01/10] change to .phpcs.xml.dist and update rules The .phpcs.xml.dist rule file is detected and implemented automatically, reducing complexity for running phpcs. The updated rules account for new wpcs sniff properties including the ability to check global prefix and i18n implementation with the correct text domain when specified. The values have been left blank so the sniffs are generic, but the rules are in place to make it easier to get started by scaffold. --- src/Scaffold_Command.php | 8 ++++---- templates/.phpcs.xml.dist | 42 +++++++++++++++++++++++++++++++++++++++ templates/phpcs.xml.dist | 20 ------------------- 3 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 templates/.phpcs.xml.dist delete mode 100644 templates/phpcs.xml.dist diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index c85edf8a0..057575696 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -575,7 +575,7 @@ private function get_output_path( $assoc_args, $subdir ) { * * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite. * * `tests/test-sample.php` is a sample file containing test cases. - * * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. + * * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. * * ## OPTIONS * @@ -706,7 +706,7 @@ function plugin( $args, $assoc_args ) { * * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite. * * `tests/test-sample.php` is a sample file containing the actual tests. - * * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. + * * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. * * Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/). * @@ -759,7 +759,7 @@ public function plugin_tests( $args, $assoc_args ) { * * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * * `tests/bootstrap.php` is the file that makes the current theme active when running the test suite. * * `tests/test-sample.php` is a sample file containing the actual tests. - * * `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. + * * `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. * * Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/). * @@ -889,7 +889,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) { $to_copy = array( 'install-wp-tests.sh' => $bin_dir, 'phpunit.xml.dist' => $target_dir, - 'phpcs.xml.dist' => $target_dir, + '.phpcs.xml.dist' => $target_dir, ); foreach ( $to_copy as $file => $dir ) { diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist new file mode 100644 index 000000000..d00af4dc9 --- /dev/null +++ b/templates/.phpcs.xml.dist @@ -0,0 +1,42 @@ + + + Generally-applicable sniffs for WordPress plugins. + + + . + vendor/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/phpcs.xml.dist b/templates/phpcs.xml.dist deleted file mode 100644 index 7044659a0..000000000 --- a/templates/phpcs.xml.dist +++ /dev/null @@ -1,20 +0,0 @@ - - - Generally-applicable sniffs for WordPress plugins - - - - - - - - - - . - - - - - */node_modules/* - */vendor/* - From e4a3d1bd195ff5124146942604993784d8ff1f66 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 09:24:37 -0400 Subject: [PATCH 02/10] add comments for blank values --- templates/.phpcs.xml.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index d00af4dc9..94d1e1d48 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -26,11 +26,13 @@ + + From b64faae020dff72345012082a433d12d586216f9 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 10:16:23 -0400 Subject: [PATCH 03/10] updates per pr feedback --- templates/.phpcs.xml.dist | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index 94d1e1d48..e991a12b5 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -1,5 +1,5 @@ - + Generally-applicable sniffs for WordPress plugins. @@ -8,19 +8,17 @@ - - + + - - - + - + From d1047f2727d2e1b4d4dbdfb616e6b140d85e1717 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 14:01:03 -0400 Subject: [PATCH 04/10] update based on more PR feedback change the the ruleset name and add a comment explaining parellel processing. --- templates/.phpcs.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index e991a12b5..492b80f12 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -1,5 +1,5 @@ - + Generally-applicable sniffs for WordPress plugins. @@ -11,7 +11,7 @@ - + From c4490679a5fcc86a3211976c82eb1d0340bd5469 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 14:06:05 -0400 Subject: [PATCH 05/10] add placeholder for prefix and textdomain rules --- templates/.phpcs.xml.dist | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index 492b80f12..93e2d0944 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -24,14 +24,14 @@ - - + + - - + + From 4160c124af2641a0fa54592bdb9977266612a328 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 14:43:02 -0400 Subject: [PATCH 06/10] add comments and update rule ref also converts spaces to tabs --- templates/.phpcs.xml.dist | 72 +++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index 93e2d0944..bc137450f 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -1,42 +1,48 @@ - Generally-applicable sniffs for WordPress plugins. + Generally-applicable sniffs for WordPress plugins. - - . - vendor/ + + . + ./vendor/ - - - - - - + + + + + + + + + - + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + From d0ac996b298f6eadba54c056c343c9c00bcdca4c Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 15:50:06 -0400 Subject: [PATCH 07/10] remove leading . --- templates/.phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/.phpcs.xml.dist b/templates/.phpcs.xml.dist index bc137450f..50f02ba19 100644 --- a/templates/.phpcs.xml.dist +++ b/templates/.phpcs.xml.dist @@ -4,7 +4,7 @@ . - ./vendor/ + /vendor/ From 2f23c5c98e27852b210d7b186b3aec89f476fa49 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 16:09:57 -0400 Subject: [PATCH 08/10] update tests and distignore for .phpcs.xml.dist --- README.md | 6 +++--- features/scaffold-plugin-tests.feature | 2 +- features/scaffold-theme-tests.feature | 2 +- features/scaffold.feature | 2 +- templates/plugin-distignore.mustache | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 70c3471bb..f2b7d367c 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ The following files are also included unless the `--skip-tests` is used: * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite. * `tests/test-sample.php` is a sample file containing test cases. -* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. +* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. **OPTIONS** @@ -288,7 +288,7 @@ The following files are generated by default: * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * `tests/bootstrap.php` is the file that makes the current plugin active when running the test suite. * `tests/test-sample.php` is a sample file containing the actual tests. -* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. +* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/). @@ -426,7 +426,7 @@ The following files are generated by default: * `bin/install-wp-tests.sh` configures the WordPress test suite and a test database. * `tests/bootstrap.php` is the file that makes the current theme active when running the test suite. * `tests/test-sample.php` is a sample file containing the actual tests. -* `phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. +* `.phpcs.xml.dist` is a collection of PHP_CodeSniffer rules. Learn more from the [plugin unit tests documentation](https://make.wordpress.org/cli/handbook/plugin-unit-tests/). diff --git a/features/scaffold-plugin-tests.feature b/features/scaffold-plugin-tests.feature index 158ea5d1f..e42358d1d 100644 --- a/features/scaffold-plugin-tests.feature +++ b/features/scaffold-plugin-tests.feature @@ -39,7 +39,7 @@ Feature: Scaffold plugin unit tests """ ./tests/test-sample.php """ - And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should exist + And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should exist And the {PLUGIN_DIR}/hello-world/circle.yml file should not exist And the {PLUGIN_DIR}/hello-world/.circleci directory should not exist And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should not exist diff --git a/features/scaffold-theme-tests.feature b/features/scaffold-theme-tests.feature index 79250adcc..b6b61dc45 100644 --- a/features/scaffold-theme-tests.feature +++ b/features/scaffold-theme-tests.feature @@ -37,7 +37,7 @@ Feature: Scaffold theme unit tests """ ./tests/test-sample.php """ - And the {THEME_DIR}/p2child/phpcs.xml.dist file should exist + And the {THEME_DIR}/p2child/.phpcs.xml.dist file should exist And the {THEME_DIR}/p2child/circle.yml file should not exist And the {THEME_DIR}/p2child/.circleci directory should not exist And the {THEME_DIR}/p2child/bitbucket-pipelines.yml file should not exist diff --git a/features/scaffold.feature b/features/scaffold.feature index e56bbb67a..c8546644a 100644 --- a/features/scaffold.feature +++ b/features/scaffold.feature @@ -224,7 +224,7 @@ Feature: WordPress code scaffolding .git .gitignore """ - And the {PLUGIN_DIR}/hello-world/phpcs.xml.dist file should contain: + And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain: """ diff --git a/templates/plugin-distignore.mustache b/templates/plugin-distignore.mustache index 6b7c70ebf..d0e70d253 100644 --- a/templates/plugin-distignore.mustache +++ b/templates/plugin-distignore.mustache @@ -21,7 +21,7 @@ phpunit.xml.dist multisite.xml multisite.xml.dist phpcs.xml -phpcs.xml.dist +.phpcs.xml.dist README.md wp-cli.local.yml yarn.lock From c22db9a249bbe8b27580e2c7519098583f78533e Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 16:20:26 -0400 Subject: [PATCH 09/10] update to handle additional phpcs rule files --- templates/plugin-distignore.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/plugin-distignore.mustache b/templates/plugin-distignore.mustache index d0e70d253..de45f50cb 100644 --- a/templates/plugin-distignore.mustache +++ b/templates/plugin-distignore.mustache @@ -20,8 +20,10 @@ phpunit.xml phpunit.xml.dist multisite.xml multisite.xml.dist +.phpcs.xml phpcs.xml .phpcs.xml.dist +phpcs.xml.dist README.md wp-cli.local.yml yarn.lock From 64920e52da73f0128cbb60220a5e0cf7ea89a31d Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Fri, 20 Jul 2018 16:26:07 -0400 Subject: [PATCH 10/10] update test for verifying the ruleset contents --- features/scaffold.feature | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/features/scaffold.feature b/features/scaffold.feature index c8546644a..e270d34e8 100644 --- a/features/scaffold.feature +++ b/features/scaffold.feature @@ -226,7 +226,10 @@ Feature: WordPress code scaffolding """ And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain: """ - + + """ + And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain: + """ """ And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain: