diff --git a/.travis.yml b/.travis.yml index 9cbdd66250e30e..dae3085e5b875b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,11 +58,7 @@ script: fi - | if [[ "$TRAVISCI" == "phpcs" ]] ; then - find . \ - -not \( -path './node_modules' \) \ - -not \( -path './vendor' \) \ - -name '*.php' \ - | xargs -d'\n' phpcs --standard=phpcs.ruleset.xml -s + phpcs fi - | if [[ "$TRAVISCI" == "js" ]] ; then diff --git a/docs/coding-guidelines.md b/docs/coding-guidelines.md index fc06a5430f6d7f..d52c747d43c047 100644 --- a/docs/coding-guidelines.md +++ b/docs/coding-guidelines.md @@ -78,3 +78,42 @@ Example: */ import VisualEditor from '../visual-editor'; ``` + +## PHP + +We use +[`phpcs` (PHP\_CodeSniffer)](https://github.com/squizlabs/PHP_CodeSniffer) +with the +[WordPress Coding Standards ruleset](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) +to run a lot of automated checks against all PHP code in this project. This +ensures that we are consistent with WordPress PHP coding standards. + +When making any changes to the PHP code in this project, it's recommended to +install and run `phpcs` on your computer. This is a step in our Travis CI +build as well, but it is better to catch errors locally. + +You will need to install `phpcs` version 2.9.x, because the 3.x versions are +not yet compatible with the WordPress coding standards. For more information see +[this issue](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/718). + +The easiest way to get `phpcs` is to download the .phar archive from the latest +2.9.x release on GitHub: +[PHP\_CodeSniffer releases](https://github.com/squizlabs/PHP_CodeSniffer/releases). + +For example: + +```sh +wget \ + https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.1/phpcs.phar \ + -O ~/bin/phpcs +chmod +x ~/bin/phpcs +``` + +(If `~/bin` is not in your `$PATH`, pick another directory that is.) + +Then you must install the `WordPress-Coding-Standards` repository and tell +`phpcs` where it lives. See instructions here: + +https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#standalone + +You should now be able to run `phpcs` from the root directory of this project. diff --git a/phpcs.ruleset.xml b/phpcs.xml similarity index 76% rename from phpcs.ruleset.xml rename to phpcs.xml index db418a3af44071..5dbac182d815b8 100644 --- a/phpcs.ruleset.xml +++ b/phpcs.xml @@ -1,10 +1,16 @@ - - Generally-applicable sniffs for WordPress plugins + + Sniffs for WordPress plugins, with minor modifications for Gutenberg + + + + gutenberg.php + ./phpunit + gutenberg.php