ikappas / vscode-phpcs

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

phpcs: The phpcs report contains invalid json. #107

Open designermonkey opened 6 years ago

designermonkey commented 6 years ago

phpcs: The phpcs report contains invalid json. Please review "Diagnosing Common Errors" in the plugin README

Same problem as #100 but none of the suggestions fix it.

My config:

{
    "phpcs.standard": "./phpcs.xml",
    "phpcs.autoConfigSearch": false
}

My PHP CS Xml:

<?xml version="1.0"?>
<ruleset name="coding standard">
    <description>coding standard</description>

    <!-- display progress -->
    <arg value="p"/>
    <!-- use colors in output -->
    <arg name="colors"/>

    <arg name="report-checkstyle" value="doc/codesniffer.xml"/>
    <arg name="report-full"/>

    <!-- inherit rules from: -->
    <rule ref="PSR2"/>
    <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

    <rule ref="PSR2">
        <exclude name="Generic.Files.LineLength"/>
    </rule>

    <!-- Paths to check -->
    <file>src</file>
    <file>tests</file>
</ruleset>

I have this config as this is set up as a composer command also.

phpcs version (local and global composer): 3.2.3

Is there any way to see any debug output for this extension? Any suggestions would be appreciated as this is driving me nuts.

rsau commented 6 years ago

What is the output of php --version ? If there is any white space or anything other than php version info on first line, vscode-phpcs outputs errors.

I have encountered 2 errors and it depends on the output before php version line.

phpcs: The phpcs report contains invalid json happened when I was getting warning about xdebug on cli.

Following error happened when I had enabled incompatible php extension accidentally.
phpcs: Unable to locate phpcs. Invalid version string encountered

Hope it helps.

jeffhuangtw commented 6 years ago

Has the same issue today, in my case, there are some special control characters in php files.

php -l target.php | vim - output: | ERROR | [ ] Expected "if (...) {\n"; found "if (...) // ^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z\n

Remove the control characters, everything works fine again.

tyler36 commented 5 years ago

Had the same problem. Was trying to debug and came across a line in #100

This error, as described in the readme, means that the output of the phpcs command is not valid json. This can happen when additional messages, are appended to the phpcs json output such as PHP Exceptions, Errors, progress, etc.

Realized my config file was set to output a full report

<arg name="report-full"/>

Disabled this line and everything worked as expected. Noticed the OP had this line in their config too. Hope this helps.

jasminmistry commented 4 years ago

Issue resolved in https://github.com/ikappas/vscode-phpcs/pull/164

nelsonc24 commented 4 years ago

I get the error only when my path has some space for example:

/Users/myuser/projects/phpcs/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path=/Users/myuser/Local Sites/plugintest/app/public/wp-content/plugins/myplugin.php

I get the error but if I run this with double-quote it works.

/Users/myuser/projects/phpcs/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path="/Users/myuser/Local Sites/plugintest/app/public/wp-content/plugins/myplugin.php"

Regards,