Fix pre-commit hooks to only check staged files
Problem
Pre-commit hooks currently run on all files in the repository:
pre-commit:
commands:
lint:
run: npm run lint # ❌ Runs on src/**/*.ts
format:
run: npm run format # ❌ Runs on src/**/*.ts
test:
run: npm run test:quick # ❌ Runs all tests
This prevents committing clean new code when pre-existing broken files exist.
Impact
- Blocks commits even when staged files are error-free
- Forces fixing ALL codebase errors before ANY commit
- Inefficient for incremental fixes
- Standard practice is to only lint/format staged files
Solution
Update lefthook.yml
to use {staged_files}
:
pre-commit:
commands:
lint:
glob: "*.{ts,js,tsx,jsx}"
run: npx eslint {staged_files} --max-warnings=0
format:
glob: "*.{ts,js,tsx,jsx,json,md,yml,yaml}"
run: npx prettier --write {staged_files}
test:
glob: "*.{ts,js,tsx,jsx}"
run: npm run test:quick -- {staged_files}
Benefits
-
✅ Only validates files being committed -
✅ Allows incremental codebase cleanup -
✅ Faster hook execution -
✅ Industry standard practice -
✅ Unblocks GitLab Wiki Manager commit
Acceptance Criteria
-
Hooks only run on staged files -
Clean files can be committed despite other errors -
GitLab Wiki Manager files commit successfully