Fix pre-commit script to properly handle multiple files and resolve ESLint warnings

This commit is contained in:
William Valentin
2025-09-07 13:34:39 -07:00
parent 8fa2d3fb60
commit 315303b120
33 changed files with 561 additions and 404 deletions

View File

@@ -69,7 +69,9 @@ run_check "prettier" "bun run pre-commit"
# 2. ESLint on staged JS/TS files only
STAGED_JS_TS_FILES=$(echo "$STAGED_FILES" | grep -E '\.(js|jsx|ts|tsx)$' || true)
if [ -n "$STAGED_JS_TS_FILES" ]; then
run_check "eslint" "bunx eslint --fix --max-warnings 0 $STAGED_JS_TS_FILES"
# Convert newlines to spaces for proper argument passing
ESLINT_FILES=$(echo "$STAGED_JS_TS_FILES" | tr '\n' ' ')
run_check "eslint" "bunx eslint --fix --max-warnings 0 $ESLINT_FILES"
else
echo "0" > "$TEMP_DIR/eslint.exit"
echo "No JS/TS files to lint" > "$TEMP_DIR/eslint.out"
@@ -87,7 +89,9 @@ fi
# 4. Markdown linting on staged markdown files
STAGED_MD_FILES=$(echo "$STAGED_FILES" | grep -E '\.md$' || true)
if [ -n "$STAGED_MD_FILES" ]; then
run_check "markdown" "bunx markdownlint-cli2 --fix $STAGED_MD_FILES || echo 'Markdown linting failed but continuing...'"
# Convert newlines to spaces for proper argument passing
MARKDOWN_FILES=$(echo "$STAGED_MD_FILES" | tr '\n' ' ')
run_check "markdown" "bunx markdownlint-cli2 --fix $MARKDOWN_FILES || echo 'Markdown linting failed but continuing...'"
else
echo "0" > "$TEMP_DIR/markdown.exit"
echo "No markdown files to lint" > "$TEMP_DIR/markdown.out"
@@ -95,7 +99,9 @@ fi
# 5. Secret scanning on staged files (optional check)
if command -v secretlint > /dev/null; then
run_check "secrets" "bunx secretlint $STAGED_FILES || echo 'Secret scanning failed but continuing...'"
# Convert newlines to spaces for proper argument passing
SECRET_FILES=$(echo "$STAGED_FILES" | tr '\n' ' ')
run_check "secrets" "bunx secretlint $SECRET_FILES || echo 'Secret scanning failed but continuing...'"
else
echo "0" > "$TEMP_DIR/secrets.exit"
echo "secretlint not available, skipping secret scanning" > "$TEMP_DIR/secrets.out"