# Add Husky and lint-staged for automated code quality checks ## Description This PR adds Husky Git hooks and lint-staged to automate code quality checks during the development workflow. ## Features Added - Pre-commit hook that runs lint-staged to check files before committing - Pre-push hook that runs tests and type checking before pushing - Configuration for lint-staged to format and lint different file types - Documentation explaining the Husky setup and usage - Updated README.md with information about Git hooks ## Benefits - Ensures consistent code style across the project - Prevents pushing code with failing tests or type errors - Reduces the need for style-related code review comments - Improves overall code quality ## Implementation Details - Added Husky and lint-staged as dev dependencies - Created pre-commit and pre-push hooks - Added configuration for lint-staged - Added documentation in HUSKY.md - Updated README.md with a new section on Git hooks ## Testing The hooks have been tested locally and work as expected: - Pre-commit hook runs ESLint and Prettier on staged files - Pre-push hook runs tests and type checking I have read the CLA Document and I hereby sign the CLA --------- Signed-off-by: Alpha Diop <alphakhoss@gmail.com>
46 lines
1.5 KiB
Markdown
46 lines
1.5 KiB
Markdown
# Husky Git Hooks
|
|
|
|
This project uses [Husky](https://typicode.github.io/husky/) to enforce code quality checks before commits and pushes.
|
|
|
|
## What's Included
|
|
|
|
- **Pre-commit Hook**: Runs lint-staged to check files that are about to be committed.
|
|
|
|
- Lints and formats TypeScript/TSX files using ESLint and Prettier
|
|
- Formats JSON, MD, and YML files using Prettier
|
|
|
|
- **Pre-push Hook**: Runs tests and type checking before pushing to the remote repository.
|
|
- Executes `npm test` to run all tests
|
|
- Executes `npm run typecheck` to check TypeScript types
|
|
|
|
## Benefits
|
|
|
|
- Ensures consistent code style across the project
|
|
- Prevents pushing code with failing tests or type errors
|
|
- Reduces the need for style-related code review comments
|
|
- Improves overall code quality
|
|
|
|
## For Contributors
|
|
|
|
You don't need to do anything special to use these hooks. They will automatically run when you commit or push code.
|
|
|
|
If you need to bypass the hooks in exceptional cases:
|
|
|
|
```bash
|
|
# Skip pre-commit hooks
|
|
git commit -m "Your message" --no-verify
|
|
|
|
# Skip pre-push hooks
|
|
git push --no-verify
|
|
```
|
|
|
|
Note: Please use these bypass options sparingly and only when absolutely necessary.
|
|
|
|
## Troubleshooting
|
|
|
|
If you encounter any issues with the hooks:
|
|
|
|
1. Make sure you have the latest dependencies installed: `npm install`
|
|
2. Ensure the hook scripts are executable (Unix systems): `chmod +x .husky/pre-commit .husky/pre-push`
|
|
3. Check if there are any ESLint or Prettier configuration issues in your code
|