Pre-commit Hooks Setup
January 6, 2026 ยท View on GitHub
This project uses Husky and lint-staged to run quality checks before commits.
What Gets Checked
Before each commit, the following checks are automatically run:
- Linting (
eslint) - Checks code quality and auto-fixes issues - Formatting (
prettier) - Ensures consistent code formatting - Type Checking (
tsc) - Validates TypeScript types - Tests (
vitest) - Runs unit and integration tests - Security Audit (
npm audit) - Checks for known vulnerabilities (non-blocking)
Installation
After cloning the repository, run:
cd frontend
npm install
The prepare script in package.json will automatically configure Git to use the .husky hooks directory.
If hooks don't work, manually configure:
# From repository root
git config core.hooksPath .husky
Note: Husky v9+ no longer requires husky install. Git hooks are configured directly via git config core.hooksPath.
How It Works
Pre-commit Hook
When you run git commit, the .husky/pre-commit hook automatically:
-
Runs
lint-stagedon staged files:- Lints TypeScript/JavaScript files with ESLint (auto-fixes issues)
- Formats all staged files with Prettier
-
Runs type checking on the entire codebase
-
Runs tests (if test files or source files changed)
-
Runs security audit (shows warnings but doesn't block commit)
Bypassing Hooks
If you need to bypass pre-commit hooks (not recommended):
git commit --no-verify -m "your message"
Warning: Only bypass hooks for emergency fixes. Always run checks manually before pushing.
Manual Checks
You can run the same checks manually:
cd frontend
# Lint
npm run lint
# Format check
npm run format:check
# Type check
npm run type-check
# Tests
npm test -- --run
# Security audit
npm run security:audit
Configuration Files
.husky/pre-commit- Pre-commit hook script.lintstagedrc.js- lint-staged configuration (what runs on staged files)package.json- Scripts and dependencies
Troubleshooting
Hooks Not Running
- Ensure Git hooks path is configured:
git config core.hooksPath(should be.husky) - If not set, run:
git config core.hooksPath .husky(from repository root) - Check hook permissions:
ls -la .husky/pre-commit(should be executable) - Verify hook exists:
test -f .husky/pre-commit && echo "Hook exists" - Test hook manually:
bash .husky/pre-commit(will fail if not in a git commit context, but syntax should be valid)
Tests Taking Too Long
The pre-commit hook runs all tests. If this is too slow:
- Run tests manually before committing:
npm test -- --run - Use
--no-verifyonly if absolutely necessary - Consider optimizing test suite or using test filtering
Security Audit Blocking Commits
Security audit is non-blocking by default. If you see warnings:
- Review the vulnerabilities:
npm audit - Fix critical issues:
npm audit fix - For non-critical issues, document why they're acceptable
CI/CD Integration
The same checks run in CI/CD pipelines:
.github/workflows/ci.yml- Runs lint, test, and type-check.github/workflows/build-release.yml- Full build pipeline with all checks
Pre-commit hooks ensure code quality before it reaches CI, saving time and resources.