Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI argument to quiet PHPCS output #969

Closed
catrope opened this issue Apr 23, 2016 · 4 comments
Closed

Add CLI argument to quiet PHPCS output #969

catrope opened this issue Apr 23, 2016 · 4 comments

Comments

@catrope
Copy link

catrope commented Apr 23, 2016

When I run phpcs --report=json and it finds errors, it simply outputs {JSON here} and nothing else. However, if it finds no errors, it outputs {JSON here}Time: 97ms; Memory: 6Mb which is not valid JSON. Other tools that consume phpcs output (the linter-phpcs plugin in Atom in my case) choke on this.

I think this may have been broken by d4abee4; #335 indicates this information previously wasn't printed when no errors were found.

$ cat blah-bad.php  | phpcs --warning-severity=1 --standard=phpcs.xml --report=json


{"totals":{"errors":1,"warnings":0,"fixable":1},"files":{"STDIN":{"errors":1,"warnings":0,"messages":[{"message":"Each PHP statement must be on a line by itself","source":"Generic.Formatting.DisallowMultipleStatements.SameLine","severity":5,"type":"ERROR","line":30,"column":25,"fixable":true}]}}}

$ cat blah-good.php  | phpcs --warning-severity=1 --standard=phpcs.xml --report=json


{"totals":{"errors":0,"warnings":0,"fixable":0},"files":{"STDIN":{"errors":0,"warnings":0,"messages":[]}}}Time: 113ms; Memory: 6Mb
@gsherwood
Copy link
Member

I don't get any time output for the JSON report.

The only time PHPCS is ever going to print runtime info for a JSON report should be when either:

  1. You are printing the report to a file, and so it prints the run time to the screen
  2. You have no errors and no warnings and you are showing progress information (-v)

Do you have progress information set to print in your phpcs.xml file by any chance? Can you remove that from your linter's settings?

@catrope
Copy link
Author

catrope commented Apr 26, 2016

Yes, you're right, I have <arg value="p"/> in phpcs.xml, can't believe I didn't check there. Removing that makes this work fine.

The behavior is still inconsistent depending on whether errors were found, but I can't complain too much that progress information is provided if the config asks for it, so this is probably invalid-ish.

@gsherwood
Copy link
Member

gsherwood commented Apr 26, 2016

The behavior is still inconsistent depending on whether errors were found

The reason it seems this way is that the error reports themselves decide if the run time information should be printed, and where it should be printed. The reports typically used in build systems (json, xml, checkstyle etc) don't print any run time info.

When you are asking for progress information to be printed to the screen, you've already got a chunk of content that can't be consumed properly by a build system. So in this case, PHPCS shows the run time information so there is no chance of the script just exiting without any report output.

Ideally, what you want is for the linter to be using a standard that doesn't show any progress information at all, so the report is the only thing that is ever produced.

Currently, the only way to do this (if you want to keep the progress info in your phpcs.xml file) is to specify a different standard file that includes the same rules but doesn't include the progress flag.

One way around this might be to add a -q option to PHPCS that allows you to quieten the progress information, but this requires the linter plugin to have an option to specify your own CLI arguments or hard-code the use of this flag.

Obviously, this isn't going to help you until a future PHPCS release and a future linter release, but I think I'll still put it on the todo because I'm sure it will be helpful in the future.

I'm going to turn this report into a feature request for a quiet flag and it seems you've got a workaround for now.

@gsherwood gsherwood changed the title --report=json returns invalid JSON when no errors found Add CLI argument to quiet PHPCS output Apr 26, 2016
gsherwood added a commit that referenced this issue Jul 1, 2016
@gsherwood
Copy link
Member

I've added the -q option, which will disable progress and verbose information from being printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants