WordPress Coding Standards in VS-Code

Install Composer and php codesniffer

scoop install composer
composer global require "squizlabs/php_codesniffer=*"

Clone WPCS in a global utils directory e.g. C:\utils\
Set phpcs config to wpcs

git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs
C:\Users\sunny\scoop\persist\composer\home\vendor\bin\phpcs --config-set installed_paths C:\utils\wpcs

Check to ensure WPCS is added

C:\Users\sunny\scoop\persist\composer\home\vendor\bin\phpcs -i

Install VS Code extensions: phpcs and phpcbf.
phpcs extension enables linting for all “PHP files in our editor.
phpcbf will try to beautify and fix our code according to the chosen coding standard.

Update settings

"phpcs.enable": true,
"phpcs.executablePath": "C:\\Users\\sunny\\scoop\\persist\\composer\\home\\vendor\\bin\\phpcs.bat",
"phpcs.standard": "WordPress",
"phpcbf.enable": true,
"phpcbf.documentFormattingProvider": true,
"phpcbf.onsave": true,
"phpcbf.executablePath": "C:\\Users\\sunny\\scoop\\persist\\composer\\home\\vendor\\bin\\phpcbf.bat",
"phpcbf.standard": "WordPress",


Posted

in

,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *