-
-
Notifications
You must be signed in to change notification settings - Fork 73
4.0 | Revise exit codes for PHPCS and PHPCBF commands #184
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
Comments
It does not look like all situations are mutually exclusive. For instance, it's possible to have fixable and unfixable errors found during the same run. This should IMO be encoded as 1+2=3. If a processing error happens, 4 should be added, and each new situation should be associated with a power of 2, so that it's possible to tell more about what happened from the exit code alone. |
@greg0ire I'm sure Greg had some idea in mind on where he wanted to go with this when he created the issue, but the above is all the info which is available. |
Personally, I would like errors and warnings to have separate exit codes, so that a coding standards error returns 1, whereas warnings with no errors returns 2 or something similar. Otherwise you have to grep the output to determine what type of error it is. This would be helpful for using PHPCS in GitLab pipelines, because exit code can be used to determine whether a pipeline is allowed to fail. GitLab allows pipelines to specify essentially a "pass with warning" state, and the pipeline stage shows as yellow (warning) instead of green (success) or red (error). I'd like an easy way to determine that from the exit code, such as 0 (success), 1 (error), 2 (warnings, no errors). |
I'd love for PHPCBF to return exit code composer coding-standards:fix
> phpcbf
F... 4 / 4 (100%)
PHPCBF RESULT SUMMARY
-------------------------------------------------------------------------------
FILE FIXED REMAINING
-------------------------------------------------------------------------------
/Users/User/Desktop/my-org/my-repo/src/php/MyClass.php 1 0
-------------------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
-------------------------------------------------------------------------------
Time: 128ms; Memory: 6MB
Script phpcbf handling the coding-standards:fix event returned with error code 1 The above example shows 1 error found and fixed. So the outcome is a success; yet it exits |
Another situation which I believe should get its own exit code: "requirements to run not met". Also see #530 |
Some more input via issue #806: @jrfnl posted:
@peterwilson responded to this with
|
Some interim thoughts on the exit code changes - nothing set in stone yet: Interim proposalCode scan,
|
Just thinking: should there be a separate exit code for when a sniff throws an error/warning/notice/deprecation ? At this moment, that would result in an error being added to the report for a file and the exit code being non-zero. However issue #30 proposes to change this by making those non-blocking in a lot of cases, but that could mean that PHPCS would finish successfully, but the scan results may be incomplete. So, what I'm really saying is: should there be a separate exit code for an incomplete run ? |
Another thought/consideration which may need discussion: PHPCS 4.0 will contain quite some changes in what is supported.
In practice, that means that in PHPCS 4.0:
In other words: there will be situations where a PHPCS/PHPCBF run can succeed, but the results may not be as expected as certain directives were ignored. What exit code should be used for this ? Should this exit with |
Looks good to me for consistency and generally makes sense! 👍 What I would love to see added is a flag that allows me to decide whether remaining non-auto-fixable issues after a This way, the CI run using |
Regarding the following:
In this case, I think something like a |
I like the idea of consistency between the two invocations of this tool (ie, I like the idea that we will be able to identify if a code-base is clean or not based on the exit code for Thinking through the use-cases for
|
I've just had a discussion with @fredden about this proposal in combination with the question I posed in #858 (errors vs warnings). To prevent future changes which may affect the exit codes having to wait until the next major release, it may be a good idea to leave some room for additional exit codes. With that in mind, I propose to change the original proposal for the exit codes to this:
This would allow for making potential additional changes while in the 4.x major and would prevent those changes having to be deferred to the 5.0 major. |
Does this mean if fixable issues are fixed, we'll still get a non-zero exit code? Or does this mean that the code base is clean after any fixing has completed? Since the purpose of code beautifier is to make changes to the code (while the purpose of code sniffer is to check for issues), it feels like code beautifier succeeds if it makes changes, hence my reasoning for wanting it to exit And to explain a little further, I like to use code beautifier in a pre-commit git hook. So if I'm about to commit some changes, I'd like it to fix any fixable issues for me automatically and exit 0 so that the commit can complete. |
Does this mean that with version 4.0, it will be possible to use the |
@paulshryock That depends. Per the above proposal, if all fixable issues are fixed and there are no non auto-fixable issues left, you'd get exit code 0. I'm inclined to implement @schlessera's suggestion for having a
I understand the desire for a zero exit code in that situation, but there will be others who will want phpcs to exit with a non-zero code if there are still non-auto-fixable things left to prevent those getting into a code base. Having the exit codes as proposed + the flag would allow to satisfy both use-cases. Does that answer your question ? |
@zdziejowski Your question is unclear to me. |
Amazing, that's exactly what I hoped for. Thank you!
Yes, 100%. Everything described sounds great to me. |
@jrfnl Now everything is clear to me:
That's fine with me. That's why I asked about the parameter |
@zdziejowski You may or may not need it. Non auto-fixable issues can be either errors or warnings. That behaviour is unchanged. |
Repost from squizlabs/PHP_CodeSniffer#2898 by @gsherwood:
Additional info posted by @jrfnl:
And some related closed issues:
And the following open PR is also related:
Related remark posted by @nelson6e65:
Question by @dfelton:
Reply by @jrfnl:
The text was updated successfully, but these errors were encountered: