Skip to content

Instantly share code, notes, and snippets.

@withzombies
Created July 19, 2025 14:33
Show Gist options
  • Save withzombies/48829733ddeef289a3f42dbb2babbd7c to your computer and use it in GitHub Desktop.
Save withzombies/48829733ddeef289a3f42dbb2babbd7c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check formatting
# This used to just enforce a check, but it was silly watching the agent attempting
# the commit two or three times after trying to fix the formatting by hand
FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB | grep -E '(.*\.(rs))$')
echo "Running formatting with cargo fmt..."
cargo fmt -- $FILES
git add $FILES
# Run Clippy linter
echo "Running cargo clippy..."
if ! cargo clippy --all-targets --all-features -- -D warnings; then
echo "Error: Clippy found warnings or errors. Please fix them before committing."
exit 1
fi
# Run tests
echo "Running tests with cargo test..."
if ! cargo test --all; then
echo "Error: Some tests failed. Please fix them before committing."
exit 1
fi
echo "All checks passed. Proceeding with commit."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment