ikappas / vscode-phpcs

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

Phpcs unknown error #119

Open riteshsv opened 6 years ago

riteshsv commented 6 years ago

C:\Users\Ritesh\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path=D:\consent.hitechos\framework\view.php - returns a valid json object.

riteshsv commented 6 years ago

i cant understand whats wrong!

DavidRT commented 6 years ago

Identical message here, anyone got a solution?

Hugues-Antoine commented 6 years ago

Identical message under Linux. By removing the --stdin-path option, by executing the command directly in a console, it works.

Hugues-Antoine commented 6 years ago

I replaced in the file server/src/linter.js at line 124

lintArgs.push(`--stdin-path=${filePath}`);

by

lintArgs.push(`${filePath}`);

It work with phpcs 3.3.0 of php 7.2.4

hengtianjiya commented 6 years ago

i have replaced lintArgs.push(--stdin-path=${filePath});

by

lintArgs.push(${filePath});

but it still not work.

phpcs 3.3.0 and PHP Version 7.0.20

is there any other wrong with it?

danhgilmore commented 6 years ago

I'm trying to use this extension on VS Code 1.26 on Windows 10, and consistently receive: "phpcs: Unable to locate phpcs. Invalid version string encountered!"

I've also updated linter.js as suggested by @Hugues-Antoine but I still get the error.

PHP 7.2.5 PHP_CodeSniffer version 3.2.3 (stable) by Squiz (http://www.squiz.net)

"phpcs.enable": true, "phpcs.standard": "WordPress", "phpcs.executablePath": "C:\xampp\php\wpcs\vendor\bin\phpcs.bat", "phpcs.autoConfigSearch": true,

benjamenjohnsondev commented 6 years ago

@danhgilmore that's a different issue - there are a bunch of closed issues about missing phpcs on windows though so check them

I fixed my issue without the solution above so posting here:

I used PHPCS from CLI and checked for error messages, running: /your/path/to/phpcs --report=json -q --encoding=UTF-8 --standard=PSR2 --error-severity=5 --warning-severity=5 --stdin-path=/path/to/a/php/file.php

I was missing the simplexml extension for php 7.1 and had it loading twice in php7.2, looks like phpcs relies on simplexml so I got the error message: PHP Fatal error: Uncaught Error: Call to undefined function PHP_CodeSniffer\Util\simplexml_load_string() in /usr/share/php/PHP/CodeSniffer/src/Util/Standards.php:115

php -m shows modules available and any php startup error messages - install the missing extension(s) and you should be good to go

In all honesty the error messages in the vscode extension could me a bit more helpful as they currently just show the extension error messages rather than passing any php error messages

jukefr commented 6 years ago

I had the wrong path to xdebug.so in my case You can find it with locate xdebug.so and add it to your php.ini

Now --stdin is not available on my version of phpcs for some reason, so I had to remove --stdin-path=${filePath} like mentioned above

aniketbarik commented 5 years ago

I was getting this error yesterday. For me it was because XDebug was being loaded twice (or from 2 places). The output of php -v said "Cannot load XDebug - it was already loaded". Removing 'zend_extension=xdebug.so' from /etc/php/7.2/mods-available/xdebug.ini fixed it for me.

karthisubramanian commented 5 years ago

I got same problem. but i have fixed --stdin-path still the same error. php -v PHP 7.0.33-7+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 3 2019 09:57:22) ( NTS ) Copyright (c) 1997-2017 The PHP Group phpcs --version PHP_CodeSniffer version 3.2.3 (stable) by Squiz (http://www.squiz.net) kindly help me out. Thanks in advance.

TheHunterDog commented 5 years ago

where is server/src/linter.js located ?

20161900240 commented 5 years ago

¿Dónde se encuentra server / src / linter.js?

yo lo busqué en el disco C:\ en el buscador de windows, pero lo edite como dicen y aún sale el error XD

niklasholm commented 4 years ago

I'm running php5.6 on Ubuntu, so I installed php7.2-cli and php7.2-xml and created wrappers that explicitly calls php7.2 instead of php5.6 and put it in /usr/local/bin, which resolved the issue for me.

Ergo, it seems the extension doesn't work with PHP 5.6.

Edit: My fix:

sudo apt install --no-install-recommends php-codesniffer php7.2-{cli,xml}

cat <<-EOF | sudo bash 
install -vm755 <(printf '%s\n' '#!/bin/sh' 'exec /usr/bin/php7.2 /usr/bin/phpcs "\$@"') /usr/local/bin/phpcs
install -vm755 <(printf '%s\n' '#!/bin/sh' 'exec /usr/bin/php7.2 /usr/bin/phpcbf "\$@"') /usr/local/bin/phpcbf
EOF
Nick-Hope commented 3 years ago

I'm running Bitnami WAMP on Windows. I was seeing errors like this in red in the lower right of my VSCode window:

phpcs: Unknown error ocurred. Please verify that C:\Users\MyName\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=6 --warning-severity=6 --stdin-path=C:\Bitnami\wampstack-7.4.12-0\apache2\htdocs\myfile.php - returns a valid json object.

Per Hugues-Antoine's answer above (thanks!) I seem to have solved this by changing lintArgs.push(--stdin-path=${filePath}); to lintArgs.push(${filePath}); at line 124 of C:\Users\Nick\.vscode\extensions\ikappas.phpcs-1.0.5\server\src\linter.js.

Nick-Hope commented 3 years ago

I spoke too soon. I have still been getting random errors, but now obviously without the --stdin-path=:

phpcs: Unknown error ocurred. Please verify that C:\Users\Nick\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=6 --warning-severity=6 C:\Bitnami\wampstack-7.4.12-0\apache2\htdocs\myfile.php - returns a valid json object.

So there must be something else going on.

As instructed by the error message, I tested by running this at a cmd prompt:

C:\Users\MyName\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=6 --warning-severity=6 C:\Bitnami\wampstack-7.4.12-0\apache2\htdocs\myfile.php

That gave this output:

Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-( {"totals":{"errors":0,"warnings":0,"fixable":0},"files":{"C:\\Bitnami\\wampstack-7.4.12-0\\apache2\\htdocs\\myfile.php":{"errors":0,"warnings":0,"messages":[]}}}

As explained in michaelAdewunmi's comment, there should not be any warnings/errors returned before the phpcs output. So the problem seems to be the Xdebug warning. I get that warning even if I run phpcs --version.

The Xdebug section of my php.ini has this:

zend_extension="C:/Bitnami/wampstack-7.4.12-0/php/ext/php_xdebug.dll"
xdebug.mode=debug
xdebug.start_with_request=yes

I can suppress the Xdebug warning by removing the last line, or changing its value, but then Xdebug no longer works in VSCode. There may be better ways to run Xdebug, which I don't yet understand. But I have been able to suppress the Xdebug error, and therefore also suppress the phpcs error, by setting xdebug.log_level=0 in my php.ini file as explained in the accepted answer here. The downside is that you may miss important Xdebug errors. An alternative is apparently to set error_log to send errors to a log file instead of printing.

Tinto-rj commented 3 years ago

you could change value of xdebug.log to your magento root folder's var/log in etc\php\7.2\mods-available\xdebug.ini. This will direct your xdebug errors to var/log folder, thus phpcs will work fine. so as xdebug.

for me it was xdebug.log="/var/www/log/xdebug.log" I changed it to xdebug.log="/var/www/magento/var/log/xdebug.log"

Now everything is working fine. I could see the xdebug errors in xdebug.log and phpcs has no issue

exetico commented 3 years ago

I've changed C:\Users\username\.vscode\extensions\ikappas.phpcs-1.0.5\server\src\linter.js line 125 from:

lintArgs.push(`--stdin-path=${filePath}`);

to:

lintArgs.push(`${filePath}`);

By testing the difference between the command with and without the parameter in PowerShell, only the last one returns a JSON-object response. With stdin-path, it reports the You must supply at least one file or directory to process error, but without stdin-path, the command returns the JSON-result.

However, in vscode, it's still failing in vscode, so it must be something in related to the vscode integration?

phpcs: Unknown error ocurred. Please verify that C:\Users\username\AppData\Roaming\Composer\vendor\bin\phpcs.bat --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 C:\Users\username\Desktop\filename.php - returns a valid json object.

I'm not sure what's going on?

I tried to disable openssl, as mentioned here, but that didn't help.

it-arjan commented 3 years ago

I changed in php.inii xdebug.log=

I've also changed C:\Users\username.vscode\extensions\ikappas.phpcs-1.0.5\server\src\linter.js line 125 from: lintArgs.push(--stdin-path=${filePath}); to: lintArgs.push(${filePath});

And I've set the path to phpcs.bat in settings

And it keeps asking if that command returns valid json, which it does

It's broken on windows10/ VSCode latest

FranciscoCaldeira commented 3 years ago

I replaced in the file server/src/linter.js at line 124

lintArgs.push(--stdin-path=${filePath});

by

lintArgs.push(${filePath});

It work with phpcs 3.3.0 of php 7.2.4

I have ubuntu 20.04, and have "No such file or directory". My .vscode only has settings.json