Skip to content

Commit a6dde6a

Browse files
committed
Optimise pre-commit hook
1 parent c7d6a0c commit a6dde6a

File tree

3 files changed

+118
-19
lines changed

3 files changed

+118
-19
lines changed

.husky/pre-commit

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
echo "🔍 Running pre-commit hook to check the code looks good... 🔍"
3+
echo "🔍 Running pre-commit hook to check staged files... 🔍"
44

55
# Load NVM if available (useful for managing Node.js versions)
66
export NVM_DIR="$HOME/.nvm"
@@ -13,27 +13,19 @@ if ! command -v pnpm >/dev/null 2>&1; then
1313
exit 1
1414
fi
1515

16-
# Run typecheck
17-
echo "Running typecheck..."
18-
if ! pnpm typecheck; then
19-
echo "Type checking failed! Please review TypeScript types."
16+
# Run lint-staged on staged files only
17+
echo "Running lint-staged on staged files..."
18+
if ! pnpm lint-staged; then
19+
echo "Lint-staged failed! Please review the issues above."
2020
echo "Once you're done, don't forget to add your changes to the commit! 🚀"
2121
exit 1
2222
fi
2323

24-
# Run lint
25-
echo "Running lint..."
26-
if ! pnpm lint; then
27-
echo "❌ Linting failed! Run 'pnpm lint:fix' to fix the easy issues."
28-
echo "Once you're done, don't forget to add your beautification to the commit! 🤩"
29-
exit 1
30-
fi
31-
32-
# Check Prettier formatting
33-
echo "Checking Prettier formatting..."
34-
if ! pnpm exec prettier --check .; then
35-
echo "❌ Prettier formatting check failed! Run 'pnpm run lint:fix' to fix formatting."
36-
echo "Once you're done, don't forget to add your formatting changes to the commit! ✨"
24+
# Run typecheck (still needed for full project context)
25+
echo "Running TypeScript typecheck..."
26+
if ! pnpm typecheck; then
27+
echo "❌ TypeScript type checking failed! Please review type errors."
28+
echo "Once you're done, don't forget to add your changes to the commit! 🚀"
3729
exit 1
3830
fi
3931

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"db:start": "docker-compose -f docker-compose.db.yml up -d",
2626
"db:stop": "docker-compose -f docker-compose.db.yml down",
2727
"db:restart": "docker-compose -f docker-compose.db.yml restart",
28-
"typecheck": "tsc",
28+
"typecheck": "tsc --noEmit --skipLibCheck",
29+
"lint-staged": "lint-staged",
2930
"preview": "pnpm run build && pnpm run start",
3031
"prepare": "husky",
3132
"prisma:generate": "prisma generate",
@@ -191,6 +192,7 @@
191192
"husky": "9.1.7",
192193
"is-ci": "^3.0.1",
193194
"jsdom": "^26.0.0",
195+
"lint-staged": "^16.1.2",
194196
"netlify-cli": "^21.1.0",
195197
"node-fetch": "^3.3.2",
196198
"prettier": "^3.4.1",
@@ -221,5 +223,14 @@
221223
"resolutions": {
222224
"@typescript-eslint/utils": "^8.0.0-alpha.30"
223225
},
226+
"lint-staged": {
227+
"*.{js,jsx,ts,tsx}": [
228+
"eslint --fix",
229+
"prettier --write"
230+
],
231+
"*.{json,md,css,scss}": [
232+
"prettier --write"
233+
]
234+
},
224235
"packageManager": "pnpm@10.10.0"
225236
}

pnpm-lock.yaml

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)