-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Disable report for phpcbf #1818
Comments
No, but which output do you want to suppress? The output showing you which files are being fixed and or the final report showing you what was done (or both)? You could always redirect STDOUT to /dev/null (or NUL for Windows, I think it is) if you want no output at all. |
Sorry, should have mentioned |
My use case: generating files with zend-code (via a composer script), which doesn't completely comply with PSR-2. Running
"generate-types": "vendor/bin/soap-client generate:types --config ./config/generate.php && phpcbf -q src/SoapTypes > /dev/null && echo \"Types have been generated to src/SoapTypes. (Ignore the error code message.)\"", Even with the report still showing, the error code message still persists. Is there a way to override that? |
The exit codes tell you what PHPCBF did, and can not be changed using config settings:
I'm not sure what config options you have, but if you can have the script error only on exit codes > 1 then it would make more sense. Otherwise, you'll need to see if you can ignore the exit code for PHPCBF if you don't actually care what it did. |
The exit code here is Composer custom scripts don't appear to have a way to override the exit code, so even though PHPCBF was 100% successful, it's still reported with a big scary red message. I have found one workaround though. The relevant part of my script: phpcbf -q src/SoapTypes > /dev/null || true It still might be useful for some to have phpcbf output no report and no error code, but for now at least, my issue is solved. I'm leaving the issue open in case you wish to pursue, but otherwise, it can be closed. |
Glad you found a solution for your case. I think an option to disable reporting (or at least change the exit code) would be helpful. |
It may be an idea to add an option to use industry standard exit codes ? I realize changing the codes now would break BC too much, but adding an option to use the more common standard of I would expect the current exit codes of Refs: |
Related: #1359 |
Another solution is to check the exit code directly after running
|
@gsherwood Is the changing of the exit code for |
Yep. Perfect time to redo them for both PHPCS and PHPCBF. I'll throw an issue in. |
Is there any way to get a code for "There are errors that can't be fixed" instead of just saying its all good because they are not fixable? eg, no namespace in psr12, snake case instead of camel case, no visibility declared etc. These are all errors and should be fixed. I would like my script to be able to tell devs "Hey there are still errors but I can't fix them" |
If you just want to know if there are errors, PHPCS is best for this. As of version 3, the PHPCS exist codes are:
So if you run PHPCS and get an exit code of 2, you can run PHPCBF and expect that some errors will be fixed. If you then run PHPCS again and get an exit code of 0, you know that no errors remain. |
Yeah, I Was hoping to avoid checking files twice with two tools. But starting with cs and then only running fixes if necessary is a decent compromise. TY :) |
Param |
There is a kind of workaround for a Composer script: Run 2 times with an OR (||), so the second time will exit {
"cs:fix": [
"phpcbf src/ tests/ config/ -p || phpcbf src/ tests/ config/ -q"
],
}
Looks ugly, non-DRY 😔, but it works. |
@nelson6e65 Alternatively you could check the exit code of the first run in the |
Yes, thanks. I tried, but only on linux and was uglier. 😅 How can I check the exit code cross-os? I use Windows, Fedora and Ubuntu. |
Cross-platform is ugly. Had to roll a custom |
Based on @nelson6e65 's code, here is more DRY albeit somewhat verbose alternative: #!/usr/bin/env bash
phpcbf "$@"
exit=$?
if [[ $exit -eq 0 || $exit -eq 1 ]]; then
exit 0
fi
exit $exit |
I created this Composer package for using https://github.com/nelson6e65/php-code-sniffer-helpers |
Is it possible to use it with code standard arguments, like |
No, sorry, @rdelbem. I checked, and all parameters are detected as files. But it already uses the Maybe I can add this detection, but I think the idea is to use the configured rules (like just running |
Having the correct xml with the desired ruleset worked perfectly. Thanks. |
Is there a way to disable reporting for
phpcbf
?Something like:
phpcbf -q --report=none .
?The text was updated successfully, but these errors were encountered: