The Windows version of this article is here.
In this article, we explain how to have your WordPress development setup in Visual Code Code on Mac OS. We will cover:
- phpcs installation on mac
- PHP Sniffer setup on Visual Studio Code
Install PHPCS using Homebrew
In the terminal window on mac, run the following
brew doctor brew install php-code-sniffer
This will have phpcs install. Run to check the status by:
You should see something like this
The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend
Install the WordPress Coding Standard
Use the git clone command to download the source code from GitHub. The last parameter indicates where you want to put the source code, we are using ~/codes/wpcs here.
git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git ~/codes/wpcs
After that is downloaded, add the coding standard to the phpcs’ config.
phpcs --config-set installed_paths ~/wpcs
Now you should see WordPress standard is added when you do `phpcs-i`
The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core
Add this to the composer
composer global require "squizlabs/php_codesniffer=*"
You can now execute it using below command:
phpcs --standard=WordPress --extensions=php ~/codes/phpfolder
Auto Fixer: phpcbf
phpcs can show you where the error is. phpcbf (PHP Code Beautifuler and Fixer) will try to fit the error for you. This tool is come with phpcs. Just simply run this:
phpcbf --standard=WordPress --extensions=php ~/codes/phpfolder
Now we are doing with setting up PHPCS and WPCS on Windows. See this article about making the WPCS auto fix automated on Visual Studio Code.