Skip to content

Instantly share code, notes, and snippets.

@JoonHoSon
Forked from hryniuk/pre-commit-cargo-fmt
Last active September 6, 2023 12:52
Show Gist options
  • Save JoonHoSon/099278855711167af608ef6dd17ff7c8 to your computer and use it in GitHub Desktop.
Save JoonHoSon/099278855711167af608ef6dd17ff7c8 to your computer and use it in GitHub Desktop.
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
CARGO_HOME=/Users/joonho/.cargo
diff=$($CARGO_HOME/bin/cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment