vscode-phpcs: error: "phpcs: Unexpected token F in JSON at position 0"
I got this error “phpcs: Unexpected token F in JSON at position 0” every time I open or save a PHP file.
My phpcs is installed system-wide, and it is working properly in my terminal.
$ php --version
PHP 5.6.29 (cli) (built: Jan 14 2017 21:05:20)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
$ which php
/usr/local/php5/bin/php
$ phpcs --version
PHP_CodeSniffer version 2.6.2 (stable) by Squiz (http://www.squiz.net)
My guess is that this extension is parsing the text report (not a JSON format report) by mistake. The error message Unexpected token F in JSON
looks like the first character of this:
$ phpcs src
FILE: test.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
8 | ERROR | [x] Whitespace found at end of line
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 72 (10 by maintainers)
Same thing here. Terminal works fine: “phpcs: Unexpected token P in JSON at position 0” in VSCode when trying to change any of the config settings such as “phpcs.standard”.
In my case, removing
<arg value="psvn"/>
from ruleset fixed the issue for me.I found a solution. Just add
<arg value="q"/>
to your rule standard (ex:ruleset.xml
) and the problem solved.I also found this problem but I fix it :
Environment:
Windows 7 / vscode 1.13.1
How to fix:
try to execute following commend in your system
the only expected output should be a json object but without any other php notice/warnning/error
if you get any other php notice/warnning/error, you should change error_reportting setting in php.ini or find other way to disable it
gooooooood luck 😉
I just released vscode-phpcs 1.0.0 which supports the VSCode 1.20+ and includes many enhancements most notable of which are:
I would like to give my thanks to all the people that helped track down issues in the previous betas and hope the new features help you get things done easier.
On that note, I am closing this issue to properly track any new issues in the new release. If you find this issue persists or any other issue please feel free to open a new ticket for v.1.0.0.
Solved by updating WP rulesets as mentioned by @iamanders (https://github.com/ikappas/vscode-phpcs/issues/32#issuecomment-323000631).
I can confirm this error was being caused from the
<arg value="np" />
line fromphpcs.xml
. This is a standard phpcs.xml definition, so this is still a valid issue.I just started using phpcs and got the same error. I could fix it by setting my coding standard on the command line and also got a lot of PHP notices, maybe not related though. (I’m using Windows)
It worked flawlessly the second time:
This don’t really sounds like a real fix to me, however it worked (somehow).
Just had the same issue and fixed it. I think this issue happen when you use phpcs 3.0. If I switch back to phpcs 2.9.1 then everything works fine.
@mbirth Have a look at https://support.microsoft.com/en-us/help/156276/cmd-exe-does-not-support-unc-names-as-the-current-directory
<arg value="q"/>
resolved this for me.@dingo-d You may need to add
<arg value="q"/>
to your xml rule set or use-q
option on command.homebrew and older php-code-sniffer rulesets aren’t friends. I was trying to use drupal-code-sniffer.
I had to do the following to get it to work on a Mac. brew install php-code-sniffer brew install drupal-code-sniffer (which installs php-code-sniffer 3.0.2 as req) brew install php-code-sniffer@2.9 which phpcs (get location installed or look at install info) copy /usr/local/Cellar/php-code-sniffer@2.9/2.9.1 folder to /usr/local/Cellar/php-code-sniffer/ brew switch php-code-sniffer 2.9.1
the Drupal ruleset I needed is working. (I know other people were suggesting composer but I didn’t want to deal with path issues right now)
I have phpcs and Drupal Coder installed via global composer. I was able to get things working by setting Drupal Coding Standards like this:
"phpcs.standard": "Drupal,DrupalPractice"
. I did receive the JSON parse error mentioned when using an absolute path to the Drupal coding standard folder.We solved this problem on my co-worker’s computer so that we uninstalled the PHPCS that was installed with homebrew and used this one instead.
Cannot use the plugin anymore. Constantly getting the error Unexpected token F in JSON at position 0.
Edit:
It has nothing todo with the plugin actually. It Can be anything wrong in your setup. For example, the Drupal code standards do not work with the latest version of Code sniffer and would throw an error while check the code. This error is returned and malform the output this plugin uses.
Try to run phpcs manually in the terminal and see if any error popup. Most likely thats the problem.