How to setup WPCS with Visual Studio Code

Step 1: Install PHP
Composer requires PHP 5.3 or higher… to install PHP (7.2) on Ubuntu, run the commands below

sudo apt install php7.2

Step 2: Install Composer

Now that PHP is installed… you can now run the commands below to install Composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

The commands above will download Composer from its maintainer page and install it into the /usr/local/bin directory… this is a local global directory for application executables…

All settings correct for using Composer Downloading... Composer (version 1.6.4) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Now simply run the commands below to test whether Composer is installed.

composer

The output should look like something below

[email protected]:~$ composer ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.6.4 2018-04-13 12:04:24 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Step 3: Install PHP_CodeSniffer with Composer

If you use Composer, you can install PHP_CodeSniffer system-wide with the following command:

composer global require "squizlabs/php_codesniffer=*"

composer global require squizlabs/php_codesniffer
composer global require wp-coding-standards/wpcs
composer global require phpcompatibility/php-compatibility
composer global require dealerdirect/phpcodesniffer-composer-installer

If installation completed rune this comment to test phpcs -i
not working this comment? You need to dow create symbolic link

sudo ln -s ~/.config/composer/vendor/bin/phpcs /usr/bin/phpcs

Step 4: Install the WordPress Coding Standards Sniffs
First go to /usr/local/bin/

git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs

Configure phpcs to use the WordPress Coding Standards sniffs

phpcs --config-set installed_paths /usr/local/bin/wpcs

To verify you’ve configured phpcs correctly, run phpcs -i . You should see the following:

The installed coding standards are PSR12, Squiz, Zend, PSR2, MySource, PSR1, PEAR, WordPress, WordPress-Docs, WordPress-Core and WordPress-Extra

Step 5:

Add this code in VSC settings.

"phpcbf.standard": "WordPress",

and install VS Code extension WordPress VS Code Extension Pack