From 5773691dbe8bc66c988bde50127bc7f840928e4b Mon Sep 17 00:00:00 2001 From: Raza Rauf Date: Mon, 19 Jan 2026 23:09:40 +0500 Subject: [PATCH] docs: add pre-commit hooks documentation to CONTRIBUTING.md --- .husky/pre-commit | 2 ++ CONTRIBUTING.md | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 index 8505dcd3..e2775762 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,5 @@ +#!/bin/sh + # Run lint-staged for formatting and linting on staged files only npx lint-staged diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbccd45a..fa8eb068 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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:**