Husky Setup
1
Install Husky
2
Add pre-commit hook
Create Make it executable:
.husky/pre-commit:.husky/pre-commit
3
Test the hook
Make a change and commit:React Doctor will run automatically before the commit completes.
Pre-Push Hook
For longer-running scans, use a pre-push hook instead:1
Create pre-push hook
Create Make it executable:
.husky/pre-push:.husky/pre-push
2
Test the hook
Lint-Staged Integration
Run React Doctor only on staged files for faster commits:1
Install lint-staged
2
Configure lint-staged
Add to Or create
package.json:package.json
.lintstagedrc.json:.lintstagedrc.json
3
Update pre-commit hook
Modify
.husky/pre-commit:.husky/pre-commit
Monorepo Hooks
Detect Changed Project
Run React Doctor only on the affected workspace project:.husky/pre-commit
Scan All Projects
.husky/pre-push
Conditional Hooks
Skip on WIP Commits
Allow WIP commits to skip the hook:.husky/pre-commit
Skip with Environment Variable
Bypass the hook when needed:.husky/pre-commit
Performance Optimization
Cache npx Downloads
Speed up hook execution by caching React Doctor:.husky/pre-commit
Skip Linting for Speed
Run only dead code detection:.husky/pre-commit
Quick Score Check
Just verify the score hasn’t dropped:.husky/pre-commit
Git Bypass
Users can always bypass hooks if needed:Complete Workflow Example
Here’s a complete setup with both pre-commit and pre-push hooks:1
Install dependencies
2
Configure lint-staged
package.json
3
Create pre-commit hook
.husky/pre-commit
4
Create pre-push hook
.husky/pre-push
5
Test the setup