ikappas / vscode-phpcs

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

phpcs: Unable to locate phpcs. Invalid version string encountered! #115

Open yeahlife opened 6 years ago

yeahlife commented 6 years ago

phpcs: Unable to locate phpcs. Invalid version string encountered!

image

what should i do ?

rsau commented 6 years ago

What is the output of php -v ?

iyashpal commented 6 years ago

I am having same issue in vs code and this is what I got after command execution:

$ php -v PHP 7.2.4 (cli) (built: Mar 28 2018 04:27:01) ( ZTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Thanks!

Hugues-Antoine commented 6 years ago

I think it's the same problem as https://github.com/ikappas/vscode-phpcs/issues/119

iyashpal commented 6 years ago

phpcs version:

$ phpcs --version PHP_CodeSniffer version 3.3.0 (stable) by Squiz (http://www.squiz.net)

Please Let me know how to solve this out.

Hugues-Antoine commented 6 years ago

I solved the problem like this : https://github.com/ikappas/vscode-phpcs/issues/119#issuecomment-395696586

guider commented 6 years ago

same issue

Samuell1 commented 5 years ago

I had same issue but blackfire was breaking it because it was loaded 2x in php.ini.

MohammadAlBanna commented 5 years ago

In my situation, running phpcs --version shows in the top line a warning message:

Warning: Xdebug MUST be loaded as a Zend extension in Unknown on l
PHP_CodeSniffer version 3.5.2 (stable) by Squiz (http://www.squiz.net)

So, first I solved Xdebug issue.

The second thing is make sure from the path: C:\Users\USER_NAME\AppData\Roaming\Composer\vendor\bin\phpcs.bat

michaelAdewunmi commented 4 years ago

I just spent the whole day checking all of the internet to get this fixed while I ignored something quite important (simply because it is unrelated to phpcs). I am using phpcs 3.5 but you should try this too no matter the version.

Really, this issue (of phpcs running in the command line but not working in vscode and giving the invalid string encountered error) is usually not a problem from phpcs or from vscode (especially when the error is invalid string encountered). I had to read the linter.js file to see where this error is coming from.

So, to fix this: First, run the command phpcs --version and check if the command does not print any warning or error before outputting a line similar to PHP_CodeSniffer version x.x.x (stable) by Squiz (HTTP://www.squiz.net).

If any error or warning (usually unrelated to phpcs) is thrown before the line showing the version, please go fix that warning or error first. According to linter.js, it expects that the first output (when it executes the phpcs.bat) must start with the PHP_CodeSniffer version string. Thus, If anything prints before the PHP_CodeSniffer version ...., then it throws the error.

So, You MUST fix any warning or error printed before the phpcs version if you want phpcs to work in VSCode. Also, ensure the path is properly set and follow all other fixes above too. So, I hope this fix works for you. cheers!