ikappas / vscode-phpcs

PHP CodeSniffer for Visual Studio Code
MIT License
128 stars 56 forks source link

phpcs: Unable to locate phpcs. Command failed: #145

Open jfkirkpatrick opened 5 years ago

jfkirkpatrick commented 5 years ago

I apologize for having to ask this question but I am going around in ever decreasing circles! I am running VS Code with Composer, Squizlab’s php_codesniffer and vscode-phpcs installed.
I am running Win 10 Pro, VS Code version 1.33.0, PHP 7.3.0, WAMP Server64 3.1.4 Because of the WAMP Server warning concerning declaring an environment variable Path for PHP, I have chosen not to declare one for php.exe. Instead I enter the value when setting up the extension. The error I am getting every time I make a change to php code is: phpcs: Unable to locate phpcs. Command failed: "C:\Users\JohnK\AppData\Roaming\Composer\vendor\bin\" --version '"C:\Users\JohnK\AppData\Roaming\Composer\vendor\bin\"' is not recognized as an internal or external command, operable program or batch file. I have setup entries in both Users Settings as well as Workspace Settings. I would prefer Global Settings as I am working on more than one project at a time. Composer located at "C:\Users\JohnK\AppData\Roaming\Composer\" composer.json.txt Composer.json file: { "require": { "squizlabs/php_codesniffer": "^3.4" } } Phpcs is located at "C:\Users\JohnK\AppData\Roaming\Composer\vendor\bin\" Php Code sniffer at: "C:\Users\JohnK\AppData\Roaming\Composer\vendor\squizlabs\" User Setting.json: { "phpcs.standard": "WordPress", "phpcs.enable": true, "phpcs.autoConfigSearch": true, "php.validate.executablePath": "c:/Program Files/PHP/php.exe", "phpfmt.php_bin": "\"C:\Program Files\PHP\php.exe\"", "workbench.colorTheme": "Oceanic Next (dimmed bg)", "phpcs.executablePath": C:\Users\JohnK\AppData\Roaming\Composer\vendor\bin\", "editor.minimap.enabled": false, "vsicons.dontShowNewVersionMessage": true, "printcode.paperSize": "letter", "printcode.fontSize": 10, "window.zoomLevel": 1 } Workspace Setting.json: { "php.validate.executablePath": "c:/Program Files/PhP/php.exe", "phpfmt.php_bin": "\"C:\Program Files\PHP\php.exe\"", "workbench.colorTheme": "Oceanic Next (dimmed bg)", "phpcs.executablePath": "C:\Users\JohnK\AppData\Roaming\Composer\vendor\bin\", "editor.fontSize": 12 }

Looked at previous submissions and was not sure they matched my situation! If you need any additional info, I would happy to provide. Any suggestion would be much appreciated. Thank you for your time. John

Borduhh commented 5 years ago

A little late to the party, but have you tried adding your composer path to your system path? That is what ended up working for me.

Open up your "Edit your system environment variables" system settings > click the "Environment Variables" button >Choose PATH under system variables > click "edit".

Add the following:

C:\wamp64\bin\php\YOURPHPVERSION
C:\ProgramData\ComposerSetup\bin

Then make sure you delete the:

"phpcs.executablePath": ""

from your settings.json in VS Code.

That should do the trick. I also highly recommend turning off "phpcs.autoConfigSearch": true as it caused a host of issues with the PHPCompability CodeSniffer update.

Cheers!

lucatsf commented 3 years ago

after having installed global and running this command phpcs --config-set installed_paths ~/.config/composer/vendor/bin/phpcs

and in vscode in the settings json file inform "phpcs.executablePath": "/home/luca/.config/composer/vendor/bin/phpcs", worked perfectly