PHP_CodeSniffer: Report warnings but return a zero exit code

I want to report to console/checkstyle any warnings, but I do not want the exit code to be > 0. Currently warnings are returning a 1.

All I could find was suppressing but this means nothing is output.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve committed this feature now. It’s only in the 2.x version because it changes the return value of the main printReport() method, which is a bit risky.

To use it, run PHPCS like this: phpcs --runtime-set ignore_warnings_on_exit true /path/to/code

Adding a comment because this issue came up in google before the wiki page. The option for this is now set using --config-set instead of --runtime-set as mentioned in this issue. The wiki has the correct commands listed, but it took me a bit to realize it was different:

Here are the current correct flags:

phpcs --config-set ignore_warnings_on_exit 1
phpcs --config-set ignore_errors_on_exit 1

Thats fine for errors, but I dont want it to happen with warnings

Another note to fellow search engine users – ignore_warnings_on_exit and ignore_errors_on_exit are only supported by phpcs, not phpcbf. (More specifically, the options are still parsed and result in Runner::run() returning 0, but Runner::runPHPCBF() ignores the return value of Runner::run() and instead returns exit codes based on the number of fixed/fixable errors in $this->reporter.)