SketchBookkeeper
10/14/2017 - 10:25 PM

Setting up PHP CodeSniffer and WordPress Standards

VS Code, Mac

PHP CodeSniffer and WordPress Coding Standards

Install phpcs

https://github.com/squizlabs/PHP_CodeSniffer

Make sure Composer in your path. If typing phpcs -h in the terminal is not a reconized command, add the following to your .bashrc or .zshrc (for Oh My ZSH).

export PATH="$PATH:$HOME/.composer/vendor/bin"

You should now be able to run the command phpcs.

Install WordPress Standards

https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards

Install following the standalone steps, placing the folder in your user.

Run phpcs --config-set installed_paths Users/your-user-name/WordPress-Coding-Standards/.

Now to run phpcs -i to make sure the coding standards were added. If you do not see any WordPress standards listed, make sure you add the complete path (from the system root) with the phpcs --config-set installed_paths command.

VS Code

Install the phpcs extension.

Add the following to your user settings.json.

"phpcs.standard": "WordPress-Extra"

If you are still getting an error add the path to the phpcs under the "phpcs.executablePath". You can get this path by typeing which phpcs.