This repository uses consistent PHP code style throughout, and enforces it using PHPCS. The standards in use are a combination of PSR-2 and WordPress coding styles, and are defined in the phpcs.xml
file.
To lint your code, make sure you have phpcs
installed, as well as the WordPress coding standards. Once you do, run yarn lint
to lint your code.
To lint your PHP code, you'll need to install PHPCS and the WordPress coding standards.
To install the latest stable version of PHPCS with Homebrew on the Mac, run:
brew install homebrew/php/php-code-sniffer
To install the WordPress coding standards and add them to the PHPCS config, run the following commands:
git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
# Add WordPress standards to PHPCS config
phpcs -i # shows the libraries installed
phpcs --config-set installed_paths <path to dir that you cloned>/wpcs
Run the linter at the command line using the following command:
yarn lint
Note that the linter only checks the headless theme and Robo file. It does not lint all of WordPress.
Atom's PHPCS linter doesn't currently work with PHPCS v3. To lint on the fly in Atom, you must install v2.9 of PHPCS, and a few Atom packages to work with it.
- Install Composer.
- Install phpcs 2.9.1 via Composer by running
php composer.phar global require "squizlabs/php_codesniffer=2.9.1"
. (Brew won't install a backversion, and phpcs 3.0 doesn't work with Atom correctly as of July 31, 2017.) - Install the WordPress Coding Standards and configure PHPCS to use them, as detailed in the section above.
- Install the following Atom packages: linter, linter-phpcs, and linter-ui-default.
- In the linter-phpcs packages' settings, set the executable path to
/Users/[username]/.composer/vendor/bin/phpcs
. - Check "Search for Configuration File" to make sure the package uses the defined
phpcs.xml
file. Restart Atom.
From there, the linter UI will show you lint warnings and errors as you code. (Instructions adapted from Jason Resnik.)