vscode-phpcs: The phpcs report contains invalid json

I’m getting this error in the vscode notification interface. "phpcs: The phpcs report contains invalid json. Please review "Diagnosing Common Errors" in the plugin README"

It just appeared recently, I also recently upgraded vscode (10.20.1) but it was working even after that, not sure why it just popped up.

I went to the README file and saw this:

Diagnosing common errors

The phpcs report contains invalid json

This error occurs when something goes wrong in phpcs execution such as PHP Notices, PHP Fatal Exceptions, Other Script Output, etc, most of which can be detected as follows: Execute the phpcs command in your terminal with --report=json and see whether the output contains anything other than valid json.

NOTE: The ‘-q’ parameter is automatically passed on phpcs v.2.6.2 and above to suppress such errors. Please update phpcs to a version >=2.6.2.

I have the latest phpcs

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

I tested the output of phpcs with a json linter and it returned no errors phpcs --report=json index.php >output.json

I am not certain what else I can do from here. Can someone please help me with an idea on how to fix this?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I encountered this issue and tracked it down to my global version of phpcs being incompatible with the Drupal standards:

https://www.drupal.org/node/2809335

(Coder requires phpcs version >=2.7.0, ❤️.0. I had the most recent version installed. Downgrading to 2.9.x solved the problem.)

@frazras More specifically try “phpcs.autoConfigSearch” : “false”

@ikappas I am using the Drupal coding standard. Here are my settings:

{
   "editor.tabSize": 2,
   "editor.renderWhitespace": "boundary",
   "files.trimTrailingWhitespace": true,
   "files.autoSave": "afterDelay",
   "git.confirmSync": false,
   "phpcs.standard": "/home/frazras/.config/composer/vendor/drupal/coder/coder_sniffer/Drupal",
   "window.zoomLevel": 1,
   "git.autofetch": true,
   "window.menuBarVisibility": "default",
   "gitlens.gitExplorer.files.layout": "tree"
}

@ikappas No, this was a global setup