Skip to content
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 pre commit infrastructure #4

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: local
hooks:
- id: rustfmt
name: autoformat
entry: .pre-commit-hooks/rustfmt.sh
language: script
files: \.rs$

- id: clippy
name: clippy_linter
entry: .pre-commit-hooks/clippy.sh
language: script
files: \.rs$
6 changes: 6 additions & 0 deletions .pre-commit-hooks/clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
cargo clippy -- -Dwarnings 2> /dev/null
clippy_exit_code=$?
if [ $clippy_exit_code != 0 ]; then
echo -e "\e[31mYour code seems to contains style violations! Run cargo clippy before committing!\e[0m" ; exit 1
fi
7 changes: 7 additions & 0 deletions .pre-commit-hooks/rustfmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
STAGED=$(git diff --name-only --cached | grep '.*\.rs')
if ! [ "$STAGED" = '' ]; then
rustfmt --check "$STAGED" || {
echo -e "\e[31mYour code is not formatted correctly! Please run rustfmt on all staged files before committing!\e[0m" ; exit 1
}
fi
Loading