Visual Studio Code: Unable to locate phpcs

I am facing this issue in Visual Studio Code. I have already tried reinstalling the phpcs extension but still facing this issue.

this is the image

Unable to locate phpcs

Please add phpcs to your global path or use the composer dependency manager to install it in your project locally in Visual studio Code


Solution 1:

I had the same issue, I did the following to fix it:

  1. Install the phpcs by using composer with composer global require squizlabs/php_codesniffer

  2. Press Command + , (Click Code -> Preferences -> Settings)

  3. Select User Settings and locate 'PHP CodeSniffer'
  4. Scroll to 'Executatble Path' and put

    /Users/your-username/.composer/vendor/bin/phpcs

This fixed the issue for me, I hope it does for you too. Cheers!

Solution 2:

open the project in the terminal and run this command

composer global require squizlabs/php_codesniffer

Hope that helps!

Solution 3:

I think uninstalling it does not solve the issue.

i had the same issue. So,

  1. Go to extensions and install the plugin...."phpcs".
  2. Search for the extension if you had install it.
  3. Disable the extension.

it resolved the issue in my VS code.

Solution 4:

On Debian based systems run as root:

apt-get install php-codesniffer

Solution 5:

From a GitHub comment.

If someone still needs help about this "Unable to locate phpcs ..." error message, try this: you just need to install phpcs globally via Composer.

  1. Install Composer from this resource if you don't have it,
  2. After Composer is installed, open a command prompt wherever you want and run this command

    composer global require squizlabs/php_codesniffer