2025-03-13 12:51:20 +08:00
|
|
|
#!/bin/bash
|
2025-10-09 10:29:20 +08:00
|
|
|
set -euo pipefail
|
2025-03-13 12:51:20 +08:00
|
|
|
|
2025-10-09 10:29:20 +08:00
|
|
|
echo "[pre-commit] Running lint-staged for JS/TS files..."
|
|
|
|
|
# Auto-fix staged JS/TS files, print warnings but don't fail commit
|
|
|
|
|
npx lint-staged || true
|
2025-10-07 17:32:49 +08:00
|
|
|
|
2025-10-09 10:29:20 +08:00
|
|
|
# Check staged Rust files
|
|
|
|
|
RUST_FILES=$(git diff --cached --name-only | grep -E '^src-tauri/.*\.rs$' || true)
|
2025-10-07 17:32:49 +08:00
|
|
|
if [ -n "$RUST_FILES" ]; then
|
2025-10-09 10:29:20 +08:00
|
|
|
echo "[pre-commit] Running rustfmt and clippy on staged Rust files..."
|
2025-10-07 17:32:49 +08:00
|
|
|
cd src-tauri || exit
|
2025-10-09 10:29:20 +08:00
|
|
|
|
2025-10-07 17:32:49 +08:00
|
|
|
# Auto-format Rust code
|
2025-06-06 21:11:14 +08:00
|
|
|
cargo fmt
|
2025-10-09 10:29:20 +08:00
|
|
|
|
|
|
|
|
# Lint with clippy, print warnings but don't fail commit
|
|
|
|
|
cargo clippy || echo "⚠️ clippy found issues, but commit will continue."
|
|
|
|
|
|
2025-06-06 21:11:14 +08:00
|
|
|
cd ..
|
2025-03-26 18:59:31 +08:00
|
|
|
fi
|
2025-03-13 12:51:20 +08:00
|
|
|
|
2025-10-09 10:29:20 +08:00
|
|
|
echo "[pre-commit] Checks completed. Some warnings may exist, please review."
|
2025-10-07 18:28:32 +08:00
|
|
|
exit 0
|