Skip to content

Phpcs and Phpcbf setup

Mosne edited this page Jul 14, 2020 · 1 revision

PHP Coding standads > Wordpress-Extra

Installing PHPCS (and phpcbf)

Download and install:

$ curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
$ curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
$ chmod +x phpcs.phar
$ chmod +x phpcbf.phar
$ sudo mv phpcs.phar /usr/local/bin/phpcs
$ sudo mv phpcbf.phar /usr/local/bin/phpcbf

Installing WPC

Download WordPress Coding standard:

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

Configuring PHPCS

Set the ABSOLUTE path to thw wpcs folder and the default rules.

$ sudo phpcs --config-set installed_paths /User/[your_user_name]/wpcs
$ sudo phpcs --config-set default_standard WordPress-Extra

Verify your configuration:

$ phpcs -i
$ phpcbf -i

Configure VScode

Install the following plugins:

Edit your configuration file:

"phpcs.standard": "WordPress-Extra",
"phpcbf.enable": true,
"phpcbf.executablePath": "phpcbf",
"phpcbf.documentFormattingProvider": true,
"phpcbf.onsave": true,
"phpcbf.standard": "WordPress-Extra",