-
Notifications
You must be signed in to change notification settings - Fork 671
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
[eng quality] pre-commit hook docs #3586
Conversation
f724130
to
cf0e6a9
Compare
Codecov Report
@@ Coverage Diff @@
## develop #3586 +/- ##
===========================================
+ Coverage 28.58% 31.26% +2.67%
===========================================
Files 298 298
Lines 275135 275135
===========================================
+ Hits 78644 86012 +7368
+ Misses 196491 189123 -7368
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed these instructions then tried to commit an invalid change (adding whitespace to the imports).
% git commit
rustfmt failed: run "cargo fmt --all -- --config group_imports=StdExternalCrate"
I ran the suggested command. I was prompted to provide a commit message as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved - as is looks good to me but I'm leaving this suggested change:
The script block below is easy to read, keeps the complicated cargo fmt command in one place for future edits, and actually formats the code if the --check fails but does not check it in.
The user is alerted that the code has been formatted and re-running the git commit -a (usually an up arrow from the terminal) will include the format changes. Its also appendable to pre-commit (only exits on failure) for when users might have an existing pre-commit hook.
2. Append the following:
CARGO_FMT="cargo fmt --all -- --config group_imports=StdExternalCrate"
$CARGO_FMT --check
CARGO_FMT_RESULT=$?
if [ $CARGO_FMT_RESULT -eq 1 ]
then
$CARGO_FMT
echo 'cargo fmt --all; applied, commit again.'
exit $CARGO_FMT_RESULT
fi
Discussed with @donpdonp and agreed there are advantages to both versions (for example, the one I proposed only runs the check command for staged files). |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Adds documentation explaining how to locally setup a pre-commit hook
Applicable issues