This is a standalone composer package for Custom WPCS and PHPCompatibilityWP rulesets.
Use Composer to install the package.
composer require --dev meom/phpcs-composer:dev-main
Lint your PHP files with the following command:
./vendor/bin/phpcs .
Or give path to lint theme folder, for example:
./vendor/bin/phpcs htdocs/wp-content/themes/theme-name
Note that by default warning are not displayed. You can change that with --severity
flag like this:
./vendor/bin/phpcs --severity=1 htdocs/wp-content/themes/theme-name
Some of the issue can be fixed using phpcbf
command:
./vendor/bin/phpcbf .
Or give path to fix theme folder, for example:
./vendor/bin/phpcbf htdocs/wp-content/themes/theme-name
Note that by default warnings are not fixed. You can fix warnings also with --severity
flag like this:
./vendor/bin/phpcbf --severity=1 htdocs/wp-content/themes/theme-name
More info about fixing PHPCS errors automatically.
Some IDE integrations of PHPCS fail to register the MEOM-default ruleset. In order to rectify this, place .phpcs.xml.dist
at your project root:
<?xml version="1.0"?>
<ruleset name="Project Rules">
<rule ref="MEOM-default" />
</ruleset>
Note this is already added in Kala Stack.
If you don't have PHP codesniffer installed globally, you might need to
.vscode
(in the root of the project).settings.json
in the folder.{
"phpcs.executablePath": "./vendor/bin/phpcs"
}
P.S. Windows is looking for file ./vendor/bin/phpcs.bat
. If that's not generated automatically in ./vendor/bin/
for some reason, test path ./vendor/squizlabs/php_codesniffer/bin/phpcs
.
.bat
files should be in that folder.