This is a standalone composer package for Custom WPCS and PHPCompatibilityWP rulesets.
- PHP 7+.
- Composer for managing PHP dependencies.
Use Composer to install the package.
composer require --dev meom/phpcs-composer:dev-mainLint 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-nameNote 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-nameSome 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-nameNote 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-nameMore 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
- Create folder
.vscode(in the root of the project). - Add file
settings.jsonin the folder. - Add the following content in the file.
{
"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.