@nesvel/husky-config
v1.0.1
Published
Shared Husky git hooks configuration for the Nesvel monorepo
Maintainers
Readme
@nesvel/husky-config
Shared Husky git hooks configuration for the Nesvel monorepo. Ensures code quality and consistency through automated pre-commit, commit-msg, and pre-push checks.
Installation
pnpm add -D husky lint-staged @commitlint/cli @nesvel/husky-configSetup
- Initialize Husky in your project root:
bunx husky init- Copy the hook files to
.husky/directory:
# Pre-commit hook
cp node_modules/@nesvel/husky-config/hooks/pre-commit .husky/pre-commit
chmod +x .husky/pre-commit
# Commit message hook
cp node_modules/@nesvel/husky-config/hooks/commit-msg .husky/commit-msg
chmod +x .husky/commit-msg
# Pre-push hook
cp node_modules/@nesvel/husky-config/hooks/pre-push .husky/pre-push
chmod +x .husky/pre-push- Configure lint-staged in your
package.json:
{
"lint-staged": {
"*.{ts,tsx,js,jsx}": ["eslint --fix", "prettier --write"],
"*.{json,md,yml,yaml}": ["prettier --write"]
}
}- Add prepare script to your root
package.json:
{
"scripts": {
"prepare": "husky"
}
}Hooks
pre-commit
Runs before each commit:
- Lints and formats staged files using
lint-staged - Ensures only valid code is committed
commit-msg
Validates commit messages:
- Enforces Conventional Commits format
- Uses
@nesvel/commitlint-config - Format:
<type>(<scope>): <subject>
pre-push
Runs before pushing to remote:
- Type checking (
pnpm run typecheck) - Tests (
pnpm run test) - Build (
pnpm run build) - Ensures only working code is pushed
Customization
You can customize the hooks by editing the copied files in .husky/ directory.
Disable specific hook temporarily
# Skip pre-commit
git commit --no-verify
# Skip pre-push
git push --no-verifyLint-staged Configuration
Example .lintstagedrc.json:
{
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{js,jsx}": ["eslint --fix", "prettier --write"],
"*.{json,md,yml,yaml}": ["prettier --write"],
"*.spec.ts": ["jest --bail --findRelatedTests"]
}Troubleshooting
Hooks not running
Make sure hooks are executable:
chmod +x .husky/pre-commit
chmod +x .husky/commit-msg
chmod +x .husky/pre-pushHooks running but failing
Check that you have all required scripts in your package.json:
typechecktestbuildlint
