Pre-Commit Quality Checks
The pre-commit hook uses lint-staged for performance, running checks only on staged files. All must pass for a commit to proceed.
Checks
1. Formatting and Linting (lint-staged)
./node_modules/.bin/lint-staged
Configuration in package.json under "lint-staged":
- JS/TS files:
prettier --write→eslint --fix - Other files:
prettier --write
Runs only on staged files for maximum performance.
2. Type Checking (TypeScript)
npx tsc --noEmit
Runs on the full project (fast enough, ensures project-wide type safety). No auto-fix — type errors must be resolved manually.
3. Unit Tests (Vitest)
./node_modules/.bin/vitest related --run $(git diff --name-only --cached)
Runs tests only for files related to staged changes using Vitest's "related" mode.
Guarantee
If pre-commit passes locally, CI must be green. If this guarantee is ever broken, it is a bug in the pipeline and must be fixed immediately.
Key Benefits
- Performance: Only processes staged files for formatting/linting
- Stability: Uses local paths (
./node_modules/.bin/) instead ofnpxto avoid $PATH issues - Smart testing: Vitest "related" mode runs only tests affected by your changes
- Auto-fix: Prettier and ESLint automatically fix issues when possible
Troubleshooting
- lint-staged fails: Check the output for specific Prettier or ESLint errors. Most issues are auto-fixed; remaining issues need manual correction.
- TypeScript fails: Read the type error carefully. Do not use
// @ts-ignoreoranyto suppress. - Tests fail: Run
npx vitestinteractively to debug. The hook only tests files related to your changes. - Hook not running: Ensure
.husky/pre-commitis executable:chmod +x .husky/pre-commit - lint-staged not found: Run
npm installto install dependencies.
Manual Check Commands
To run checks manually before committing:
# Format all files
npm run format
# Lint all files
npm run lint
# Type check
npm run typecheck
# Run full test suite
npm test
Converted and distributed by TomeVault — claim your Tome and manage your conversions.