This project uses Husky and lint-staged to ensure code quality and consistency before commits.
- Pre-commit: Runs lint-staged on staged files
- Commit-msg: Validates commit messages using commitlint
Automatically runs on staged files:
- JavaScript/TypeScript files (
.js,.jsx,.ts,.tsx):- ESLint with auto-fix
- Prettier formatting
- Other files (
.json,.css,.md):- Prettier formatting
- Commitizen: Interactive commit message creation
- Commitlint: Validates commit message format
Use the interactive commit tool for conventional commits:
npm run commit
# or
git cz# Lint and fix issues
npm run lint:fix
# Format all files
npm run format
# Check formatting without fixing
npm run format:checkFollow conventional commit format:
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringperf: Performance improvementstest: Adding or updating testsbuild: Build system changesci: CI/CD changeschore: Maintenance tasksrevert: Reverting changes
Examples:
feat(auth): add user login functionality
fix(ui): resolve button alignment issue
docs: update API documentation
chore: update dependencies
- Before Commit: When you run
git commit, Husky triggers the pre-commit hook - Lint-staged: Only processes staged files, running ESLint and Prettier
- Auto-fix: ESLint automatically fixes fixable issues
- Format: Prettier formats the code consistently
- Validation: If there are unfixable errors, the commit is blocked
- Commit Message: Commitlint validates the commit message format
- Consistent Code Quality: All code is linted and formatted before commits
- Clean Git History: Only properly formatted code enters the repository
- Team Consistency: Everyone follows the same coding standards
- Conventional Commits: Standardized commit messages for better changelog generation
- Faster Reviews: Less time spent on formatting issues in code reviews
If the pre-commit hook fails:
- Fix the linting errors shown in the output
- Re-stage the files:
git add <file> - Try committing again
If you absolutely need to bypass hooks (emergency fixes):
git commit --no-verify -m "emergency fix"To update the pre-commit configuration, modify:
package.json- lint-staged configuration.husky/pre-commit- pre-commit hook script.husky/commit-msg- commit message validationcommitlint.config.js- commit message rules