Skip to content

Instantly share code, notes, and snippets.

@hryniuk
Last active February 7, 2024 09:21
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hryniuk/e3f4ae34e37947d0ff55a3f63add90f8 to your computer and use it in GitHub Desktop.
Save hryniuk/e3f4ae34e37947d0ff55a3f63add90f8 to your computer and use it in GitHub Desktop.
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
diff=$(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
@Sparkenstein
Copy link

Might wanna add cargo clippy for linting as well. thanks for the scripts :D

@hryniuk
Copy link
Author

hryniuk commented Sep 8, 2020

Thanks for the suggestion! I didn't notice I made it public 😁

@pablogomez93
Copy link

Might wanna add cargo clippy for linting as well. thanks for the scripts :D

Running cargo clippy before each commit will end up with clippy downloading all your dependencies and compiling your entire project every time you commit, that could be very very bothering 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment