PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
806 stars 47 forks source link

Only return a non-zero exit code if the number of errors is greater than zero #282

Closed kczx3 closed 6 months ago

kczx3 commented 6 months ago

Is your feature request related to a problem?

No

Describe the solution you'd like

I was hoping for a way to make the primary script only return a non-zero exit code if there are only ERRORs, regardless of the number of WARNINGs. For my usecase, I would like warnings to still be emitted (so the -n flag won't work here) but I don't want the process to exit with a code greater than zero. The reasoning here is that I use GitLab CI/CD and a non-zero exit code causes the job to fail. I don't want the job to fail if there are only warnings but I do still want them to be output. Hopefully this makes sense.

src/Runner.php calls $this->run() and names the return value as $numErrors which isn't technically true as run actually adds the total errors and warnings for this value. Perhaps an additional command line flag could be added to flex this behavior.

Additional context (optional)

jrfnl commented 6 months ago

Feature is already available, you only have to use it: https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-warnings-when-generating-the-exit-code

Note: you can use --runtime-set ... instead of --config-set ... if you only want to use it for a single run/specific command and not always.

Also note that you can set this via your custom ruleset as well using <config name="ignore_warnings_on_exit" value="1"/>.

kczx3 commented 6 months ago

Ugh sorry 🤦‍♂️ I have a hard time navigating the documentation. Thought I looked everywhere

jrfnl commented 6 months ago

No worries, at least now you know.