mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
chore: light hook
This commit is contained in:
@@ -1,45 +1,24 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Run lint-staged to handle formatting and linting for JS/TS files
|
||||
# This handles prettier and eslint --fix automatically
|
||||
npx lint-staged
|
||||
|
||||
# Check for any remaining linting errors in JS/TS files that weren't fixed automatically
|
||||
# Only run this if JS/TS files are staged (lint-staged already handled these)
|
||||
JS_FILES=$(git diff --cached --name-only | grep -E '\.(ts|tsx|js|jsx)' || true)
|
||||
|
||||
if [ -n "$JS_FILES" ]; then
|
||||
echo "Verifying no remaining linting issues in staged files..."
|
||||
# Use --max-warnings 0 to ensure no warnings either
|
||||
if ! pnpm lint:staged --max-warnings 0; then
|
||||
echo "ESLint found unfixable issues or warnings in staged files. Please fix them before committing."
|
||||
echo "Files affected: $JS_FILES"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for staged Rust files and handle them
|
||||
RUST_FILES=$(git diff --cached --name-only | grep -E '^src-tauri/.*\.(rs)$' || true)
|
||||
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
|
||||
|
||||
# Check staged Rust files
|
||||
RUST_FILES=$(git diff --cached --name-only | grep -E '^src-tauri/.*\.rs$' || true)
|
||||
if [ -n "$RUST_FILES" ]; then
|
||||
echo "Running rustfmt and clippy on staged Rust files..."
|
||||
echo "[pre-commit] Running rustfmt and clippy on staged Rust files..."
|
||||
cd src-tauri || exit
|
||||
|
||||
# Auto-format Rust code
|
||||
cargo fmt
|
||||
# Check if there are still formatting issues after auto-formatting
|
||||
if ! cargo fmt -- --check; then
|
||||
echo "rustfmt still found formatting issues after auto-formatting."
|
||||
cd ..
|
||||
exit 1
|
||||
fi
|
||||
# Run clippy for linting
|
||||
if ! cargo clippy; then
|
||||
echo "clippy found issues. Please fix them before committing."
|
||||
cd ..
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Lint with clippy, print warnings but don't fail commit
|
||||
cargo clippy || echo "⚠️ clippy found issues, but commit will continue."
|
||||
|
||||
cd ..
|
||||
fi
|
||||
|
||||
# Allow commit
|
||||
echo "[pre-commit] Checks completed. Some warnings may exist, please review."
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user