Best practices, tools, and processes we follow in ColoredCow.
This document covers how to setup PHP Code Sniffer to sniff WordPress coding standards in VS Code for Windows and Mac OS.
C:\Users\username\AppData\Roaming\Composer
.composer require squizlabs/php_codesniffer
on your composer directory.C:\Users\username\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin
to your environment variables PATH
.phpcs --version
on the terminal.composer require wp-coding-standards/wpcs
on your composer directory.vendor
directory in your composer directory and clone PHPCompatibility package by running git clone https://github.com/wimg/PHPCompatibility.git
.composer
directory and link wpcs and phpcompatibility standards with phpcs by running phpcs --config-set installed_paths C:\Users\username\AppData\Roaming\Composer\vendor\PHPCompatibility,C:\Users\username\AppData\Roaming\Composer\vendor\wp-coding-standards\wpcs
.phpcs -i
.settings.json
and add following lines to it:
"phpcs.enable": true,
"phpcs.executablePath": "C:\\Users\\username\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcs.bat",
"phpcs.standard": "WordPress",
"phpcbf.enable": true,
"phpcbf.documentFormattingProvider": true,
"phpcbf.onsave": true,
"phpcbf.executablePath": "C:\\Users\\username\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcbf.bat",
"phpcbf.standard": "WordPress",
"[php]": {
"editor.defaultFormatter": "persoderlind.vscode-phpcbf"
}
composer global require "squizlabs/php_codesniffer=*"
git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs
composer
directory and link wpcs and phpcompatibility standards with phpcs by running
/path/to/composer/vendor/bin/phpcs --config-set installed_paths /path/to/WPCS, /path/to/another-standards
Note:
In the place of /path/to/composer/vendor/bin/phpcs
add the path of composer
located in your system.
/path/to/WPCS
add the path where wpcs
is stored./path/to/composer/vendor/bin/phpcs -i
OUTPUT:
The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core.
settings.json
and add following lines to it:
"phpcs.enable": true,
"phpcs.executablePath": "/path/to/composer/vendor/bin/phpcs",
"phpcs.standard": "WordPress"
"phpcbf.enable": true,
"phpcbf.documentFormattingProvider": true,
"phpcbf.onsave": true,
"phpcbf.executablePath": "/path/to/composer/vendor/bin/phpcbf",
"phpcbf.standard": "WordPress",
"[php]": {
"editor.defaultFormatter": "persoderlind.vscode-phpcbf"
}