docs: Add pre-commit hook setup instructions for type validation

Document optional local Git pre-commit hook configuration to catch
type drift before commits. Also document Husky alternative.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-30 21:02:00 +02:00
parent 59c92f9a83
commit e24b1241fb

View File

@@ -111,6 +111,34 @@ The script returns:
- **Exit 2:** Backend is not accessible (set `BANGUI_BACKEND_URL` if needed)
- **Exit 3:** Type generation failed
### Pre-Commit Hook Setup (Local Development)
To catch type drift locally before committing, set up a Git pre-commit hook:
1. **Create `.git/hooks/pre-commit`:**
```bash
#!/bin/bash
# Validate types before commit
cd frontend
npm run validate:types
if [ $? -ne 0 ] && [ $? -ne 2 ]; then # Allow hook to skip if backend unavailable
echo "❌ Types out of sync. Run 'npm run generate:types' and commit the changes."
exit 1
fi
```
2. **Make it executable:**
```bash
chmod +x .git/hooks/pre-commit
```
3. **Alternative: Use Husky** (if your project has Husky configured)
```bash
npx husky add .husky/pre-commit "cd frontend && npm run validate:types"
```
**Note:** The pre-commit hook is optional and local only. The CI/CD pipeline will always validate types, so types cannot drift even without a local hook.
---
## 3. Type Safety in API Calls