Skip to content

Commit f6c650a

Browse files
committed
4.0 | Document the new (and old) exit codes and the ignore_non_auto_fixable_on_exit flag
1 parent a8318ca commit f6c650a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

wiki/Advanced-Usage.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [The Level Map](#the-level-map)
1919
* [Printing Verbose Token Processing Output](#printing-verbose-token-processing-output)
2020
* [Quieting Output](#quieting-output)
21+
* [Understanding the Exit Codes](#understanding-the-exit-codes)
2122

2223
***
2324

@@ -524,3 +525,35 @@ For example, the ScopeIndentSniff executes on the if statement's token only, but
524525
If a coding standard or configuration file includes settings to print progress or verbose output while running PHP_CodeSniffer, it can make it difficult to use the standard with automated checking tools and build scripts as these typically only expect an error report. If you have this problem, or just want less output, you can quieten the output of PHP_CodeSniffer by using the `-q` command line argument. When using this quiet mode, PHP_CodeSniffer will only print report output, and only if errors or warnings are found. No progress or verbose output will be printed.
525526

526527
<p align="right"><a href="#table-of-contents">back to top</a></p>
528+
529+
530+
## Understanding the Exit Codes
531+
532+
As of PHP_CodeSniffer 4.0.0, exit codes are cumulative and composed as follows:
533+
534+
| Exit code | Meaning |
535+
| --------- | ------------------------------------------------------------------------------------------------------- |
536+
| `0` | clean code base / successful non-scan request (_help/documentation/etc_) |
537+
| `1` | issues found/remaining, auto-fixable |
538+
| `2` | issues found/remaining, non-auto-fixable |
539+
| `4` | failure to fix some files/fixer conflict (phpcbf only) |
540+
| `16` | processing error - blocking the actual run of PHP_CodeSniffer, like a parse error in an XML ruleset |
541+
| `64` | requirements for running not met (i.e. minimum PHP version doesn't comply, missing required extensions) |
542+
543+
Example: when running `phpcs`, if both auto-fixable as well as non-auto-fixable issues are found, the exit code will be `3` (`1` + `2`).
544+
545+
The exit codes can be influenced by the following configuration flags: [`ignore_errors_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-errors-when-generating-the-exit-code), [`ignore_warnings_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-warnings-when-generating-the-exit-code) and [`ignore_non_auto_fixable_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-non-auto-fixable-issues-when-generating-the-exit-code).
546+
547+
548+
In PHP_CodeSniffer 3.x, the exit codes were:
549+
550+
| `phpcs` | | `phpcbf` | |
551+
| ------- | -------------------- | -------- | -------------------------------------------------------- |
552+
| `0` | no errors found | `0` | no fixable errors were found, so nothing was fixed |
553+
| `1` | errors found | `1` | all fixable errors were fixed correctly |
554+
| `2` | fixable errors found | `2` | PHPCBF failed to fix some of the fixable errors it found |
555+
| `3` | processing error | `3` | processing error |
556+
557+
And the following configuration flags were available: [`ignore_errors_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-errors-when-generating-the-exit-code), [`ignore_warnings_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-warnings-when-generating-the-exit-code).
558+
559+
<p align="right"><a href="#table-of-contents">back to top</a></p>

wiki/Configuration-Options.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [Setting the PHP version](#setting-the-php-version)
1414
* [Ignoring errors when generating the exit code](#ignoring-errors-when-generating-the-exit-code)
1515
* [Ignoring warnings when generating the exit code](#ignoring-warnings-when-generating-the-exit-code)
16+
* [Ignoring non-auto-fixable issues when generating the exit code (PHP_CodeSniffer >= 4.0.0)](#ignoring-non-auto-fixable-issues-when-generating-the-exit-code-php_codesniffer--400)
1617
* Setting tool paths
1718
* [CSSLint](#setting-the-path-to-csslint)
1819
* [Google Closure Linter](#setting-the-path-to-the-google-closure-linter)
@@ -235,6 +236,19 @@ $ phpcs --config-set ignore_warnings_on_exit 1
235236
<p align="right"><a href="#table-of-contents">back to top</a></p>
236237
237238
239+
## Ignoring non-auto-fixable issues when generating the exit code (PHP_CodeSniffer >= 4.0.0)
240+
241+
By default, PHP_CodeSniffer will exit with a non-zero code if any errors or warnings are found, whethere these are auto-fixable or not.
242+
If you want to display non-autofixable errors and warnings to the user, but still return with a zero exit code if non-auto-fixable issues are found, you can set the `ignore_non_auto_fixable_on_exit` configuration option.
243+
This option is typically used by automated build tools so that a `phpcbf` run can exit with `0` if it fixed all fixable issues, but there are still some non-auto-fixable issues remaining.
244+
245+
```bash
246+
$ phpcs --config-set ignore_non_auto_fixable_on_exit 1
247+
```
248+
249+
<p align="right"><a href="#table-of-contents">back to top</a></p>
250+
251+
238252
## Generic Coding Standard Configuration Options
239253
240254
### Setting the path to CSSLint

0 commit comments

Comments
 (0)