From e3af07b1ebab015494c5594a7b5ec65dcfd4d277 Mon Sep 17 00:00:00 2001 From: Matt Hess Date: Wed, 25 Feb 2026 19:02:06 +0000 Subject: [PATCH] Add fmt + clippy CI checks to pre-commit hook - Integrate cargo fmt --check and clippy -Dwarnings into .githooks/pre-commit - Matches CI's RUSTFLAGS="-Dwarnings" to catch issues before push - Runs before existing secret detection checks --- .githooks/pre-commit | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c3cb220..4e8491b 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,6 +1,33 @@ #!/bin/bash -# Pre-commit hook to prevent accidental secret commits +# Pre-commit hook: +# 1. cargo fmt --check (matches CI) +# 2. cargo clippy -Dwarnings (matches CI RUSTFLAGS) +# 3. Secret detection (mnemonic phrases, hex keys) +# +# Skip with: git commit --no-verify +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# ── Rust CI checks ────────────────────────────────────────────────── +echo -e "${YELLOW}pre-commit: checking formatting...${NC}" +if ! cargo fmt --all -- --check 2>/dev/null; then + echo -e "${RED}FAILED:${NC} cargo fmt --all -- --check" + echo -e "Run ${GREEN}cargo fmt --all${NC} to fix, then re-stage and commit." + exit 1 +fi + +echo -e "${YELLOW}pre-commit: running clippy (-Dwarnings)...${NC}" +if ! RUSTFLAGS="-Dwarnings" cargo clippy --workspace --all-targets 2>&1; then + echo -e "${RED}FAILED:${NC} cargo clippy --workspace --all-targets" + exit 1 +fi + +echo -e "${GREEN}pre-commit: fmt + clippy passed${NC}" + +# ── Secret detection ──────────────────────────────────────────────── echo "Checking for potential secrets..." # Patterns to detect