I am slowly moving away from Sublime Text to Microsoft’s Visual Studio Code due to VS Code’s superior feature-set like a built-in file navigation tree (which is better than ST’s SideBarEnhancements package), IntelliSense and built-in Git.
Below are the steps to have VS Code automatically sniff and display warnings/errors (if any) in your PHP files per WordPress Coding Standards.
In the system terminal (navigate to your home directory, if you are elsewhere) run
composer create-project wp-coding-standards/wpcs --no-dev
Running this command will
- install WordPress standards into ~/wpcs directory.
- install PHP_CodeSniffer.
- register WordPress standards in PHP_CodeSniffer configuration.
phpcscommand available from ~/wpcs/vendor/bin.
ln -s ~/wpcs/vendor/bin/phpcs /usr/local/bin/phpcs
This will create
/usr/local/bin/phpcs as an alias or symbolic link to
~ is your home directory (Ex.:
Go to Control Panel. Search for
path and click on “Edit the system environment variables”.
Click on “Environment Variables…” in the System Properties’ Advanced tab.
In the bottom “System variables” section, select
Path and click Edit.
Add a new entry having this path:
Admin is your current admin-level username.
In VS Code, go to Extensions, search for
phpcs and install it.
Bring up your user settings by pressing ⌘, and add
Restart VS Code.
- To check the value of $PATH environment in a terminal run
- To add a directory to $PATH, run
open ~/.bash_profile. Then in the text editor add
/Users/sridharkatakam/wpcs/vendor/binis the directory whose path is to be added.