Search code examples
phpcs

phpcs: Referenced sniff "WordPress" does not exist


I've installed phpcs by following this answer, and added the following to my Visual Code settings.json:

{
    "phpcs.enable": true,
    "phpcs.composerJsonPath": "wp-content/themes/wprig/composer.json",
    "phpcs.standard": "WordPress",
    "phpcs.executablePath": "/Users/Chris/.composer/vendor/bin/phpcs",
}

However, when I edit a PHP file in a WordPress theme, Visual Code displays an error @ bottom right:

phpcs: Referenced sniff "WordPress" does not exist

If I run phpcs -i I receive: The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1 and PSR12.

How do I install the WordPress coding standard for phpcs please?

Update: I followed the steps @ this tutorial, specifically running:

./vendor/bin/phpcs --config-set installed_paths /Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs

(I receive a positive confirmation after this). And I add "phpcs.standard": "WordPress", to VS Code's settings.json, however the error remains, even after restarting VS Code.

I have the WordPress coding standards directory @ /Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs.

Help appreciated.


Solution

  • Looks like you have cloned wpcs @ WordPress project. Try to clone wpcs into another dir e.g.

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

    and add its path to the PHP_CodeSniffer configuration

    phpcs --config-set installed_paths /Applications/AMPPS/www/wpcs
    

    Dot't forget to remove /Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs from themes dir.