Skip to content

Commit

Permalink
add pre commit infrastructure (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Hock authored Jan 13, 2024
1 parent f06a3b8 commit 0616f08
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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

0 comments on commit 0616f08

Please sign in to comment.