-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Add Formatting Fail Flag for CI Use #923
Conversation
Thanks for the contribution! A couple of points from me:
|
I'm open to another flag, sure. I'll leave that up to you, just let me know. I'd suggest I can look at adding tests too. |
I like |
pushed the flag change now. Working on tests later. |
Ok, I've added both a pass and fail test case @joerdav , as well as adding the flag to the args structs of the other related test for completeness. Let me know what you think. |
I think this is my last comment now, thanks for amending based on the last ones! I think the current wording implies it is "for CI", but I think that's just one use case. I think it may be better to use wording like "This flag does X, this could be used in CI to check blah blah blah" rather than "This flag does X for use in CI" Does that make sense? |
Yes, that makes sense, and better conveys the meaning I was hoping to convey. I like that wording. good feedback! |
Co-authored-by: Joe Davidson <[email protected]>
Ok, ready to rock and roll. |
A common use with linters and formatters is checking in CI and failing if the formatter required any changed. This ensures that branches are never merged without the formatter being run.
This PR implements this functionality by tracking the number of files changed, and allowing the user to return an error exit code if
-fail
is provided, subsequently failing the CI job if formatting was not done before commit.This PR also has the side benefit of providing additional user situational awareness as it now prints the number of changed files on every format run, even if the CI-fail flag is not used.
After merge, users can add the following to their CI to validate template formatting.
Results
fmt
's help now looks like this:A normal run now looks like this (note the
changed
field) if no changes made.A normal run now looks like this (note the
changed
field) if changes are made.The new flag run now looks like this, if changes are made.
In the above case, the unix exit code is also
1
instead of the normal0
.