From 92327f08d451cdd663bbdd73e31cf452a3d7c506 Mon Sep 17 00:00:00 2001 From: Tate Date: Wed, 2 Oct 2024 23:31:19 -0600 Subject: [PATCH] make the rust checks work if code is in a sub directory (#5) --- pre-commit-hooks/rust-fmt.sh | 4 ++++ pre-commit-hooks/rust-lint.sh | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pre-commit-hooks/rust-fmt.sh b/pre-commit-hooks/rust-fmt.sh index a848185..a2bac9b 100755 --- a/pre-commit-hooks/rust-fmt.sh +++ b/pre-commit-hooks/rust-fmt.sh @@ -3,9 +3,13 @@ # Exit immediately if a command exits with a non-zero status set -e +# Get the directory to run cargo fmt in, default to current directory +RUST_DIR=${1:-.} + # Function to format rust code run_cargo_fmt() { echo "Executing 'cargo fmt'" + cd "$RUST_DIR" cargo fmt } diff --git a/pre-commit-hooks/rust-lint.sh b/pre-commit-hooks/rust-lint.sh index e0b9340..1746eac 100755 --- a/pre-commit-hooks/rust-lint.sh +++ b/pre-commit-hooks/rust-lint.sh @@ -3,12 +3,16 @@ # Exit immediately if a command exits with a non-zero status. set -e +# Get the directory to run cargo fmt in, default to current directory +RUST_DIR=${1:-.} + # Function to run linters on the rust project run_linter() { echo "Executing clippy" # Run the linter and capture the exit status set +e + cd "$RUST_DIR" cargo clippy -- -D warnings local linting_result=$? set -e