Automated WordPress coding standards checks using Atom

After being frustrated by missing simple coding style errors in my WordPress contributions, I finally decided to employ some tooling to help automate the process of checking my code. This is how I set up my machine so the Atom editor will automatically check code for WordPress Coding Standards.

Install PHP CodeSniffer

PHP_CodeSniffer is an automated tool for checking for coding style based on a set of defined standards. I followed the installation instructions on the project’s GitHub page to download the .phar files and then I moved them into my /usr/local/bin/ directory like this:

mv phpcs.phar /usr/local/bin/phpcs
mv phpcbf.phar /usr/local/bin/phpcbf

If everything went well, you should be able to type phpcs --version in the command line and see version information returned.

Install WordPress Coding Standards rules

The WordPress Coding Standards project is maintained on GitHub. I followed the standalone installation instructions to clone the project to my usr/local/bin directory and configure phpc to make use of the WordPress coding standards with the following command:

phpcs --config-set installed_paths /usr/local/bin/wpcs

Configuring the Atom Editor

Finally, to be automatically notified about WordPress coding style issues in my editor, I followed the setup instructions for Atom on the WordPress Coding Standards GitHub page using the linter-phpcs package for Atom.

From now on, I hope to spend less time worrying about any coding standards issues with my code and be more confident in the overall quality of the work that I’m doing.