docs: add pre-commit hooks documentation to CONTRIBUTING.md

This commit is contained in:
Raza Rauf
2026-01-19 23:09:40 +05:00
parent dd04429482
commit 5773691dbe
2 changed files with 30 additions and 4 deletions

2
.husky/pre-commit Normal file → Executable file
View File

@@ -1,3 +1,5 @@
#!/bin/sh
# Run lint-staged for formatting and linting on staged files only
npx lint-staged

View File

@@ -189,7 +189,31 @@ src/__tests__/
└── web/ # Web interface tests
```
## Linting
## Linting & Pre-commit Hooks
### Pre-commit Hooks
This project uses [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/lint-staged/lint-staged) to automatically format and lint staged files before each commit.
**How it works:**
1. When you run `git commit`, Husky triggers the pre-commit hook
2. lint-staged runs Prettier and ESLint only on your staged files
3. If there are unfixable errors, the commit is blocked
4. Fixed files are automatically re-staged
**Setup is automatic** — hooks are installed when you run `npm install` (via the `prepare` script).
**Bypassing hooks (emergency only):**
```bash
git commit --no-verify -m "emergency fix"
```
**Running lint-staged manually:**
```bash
npx lint-staged
```
### Manual Linting
Run TypeScript type checking and ESLint to catch errors before building:
@@ -214,9 +238,9 @@ ESLint is configured with TypeScript and React plugins (`eslint.config.mjs`):
- `@typescript-eslint/no-unused-vars` - Warns about unused variables
- `prefer-const` - Suggests const for never-reassigned variables
**When to run linting:**
- Before committing changes
- After making significant refactors
**When to run manual linting:**
- Pre-commit hooks handle staged files automatically
- Run full lint after significant refactors: `npm run lint && npm run lint:eslint`
- When CI fails with type errors
**Common lint issues:**