Loading...
Loading...
Configures Husky, lint-staged, commitlint, and Python pre-commit
npx skill4agent add levnikolaevich/claude-code-skills ln-742-precommit-setup| Technology | Hook Manager | Staged Linting | Commit Validation |
|---|---|---|---|
| Node.js | Husky | lint-staged | commitlint |
| Python | pre-commit | pre-commit hooks | pre-commit hook |
| Mixed | Both (if needed) | Stack-specific | commitlint |
| Tool | Indicators |
|---|---|
| Husky | |
| pre-commit | |
| lint-staged | |
| commitlint | |
npm install -D husky
npx husky init.husky/.husky/pre-commitpreparepip install pre-commit
# OR with uv:
uv add --dev pre-commit
pre-commit install.git/hooks/pre-commit.pre-commit-config.yamlnpm install -D lint-staged.lintstagedrc.mjsCRITICAL FIX: For .NET files, use correct syntax:is WRONG Use:"*.cs": "dotnet format --include"or run dotnet format separately"*.cs": "dotnet format whitespace --include"
.pre-commit-config.yamlrepos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-formatnpm install -D @commitlint/cli @commitlint/config-conventionalcommitlint.config.mjsecho 'npx --no -- commitlint --edit "$1"' > .husky/commit-msg.pre-commit-config.yaml - repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]# Create a file with lint issues
echo "const x=1" > test-file.ts
git add test-file.ts
git commit -m "test: verify hooks"
# Expected: lint-staged runs, either fixes or blocksgit commit --allow-empty -m "bad message"
# Expected: commitlint rejects
git commit --allow-empty -m "test: valid message format"
# Expected: commit succeedsrm test-file.ts
git reset HEAD~1 # If test commit was madeRULE 1: Husky requires Git repository (first).git init
RULE 2: lint-staged MUST have linters configured first (run ln-741 before ln-742).
RULE 3: Documentescape hatch for emergency commits.--no-verify
RULE 4: pre-commit hooks should auto-fix when possible (flag).--fix
git commit --no-verify| File | Purpose |
|---|---|
| husky_precommit_template.sh | Husky pre-commit hook |
| husky_commitmsg_template.sh | Husky commit-msg hook |
| lintstaged_template.mjs | lint-staged configuration |
| commitlint_template.mjs | commitlint configuration |
| precommit_config_template.yaml | Python pre-commit config |
| hooks_guide.md | Detailed hooks guide |
| Error | Cause | Resolution |
|---|---|---|
| Husky not running | Missing prepare script | Run |
| lint-staged fails | Missing linter | Run ln-741 first |
| pre-commit not found | Not in PATH | |
| Hooks not triggering | Git hooks disabled | Check |
| Windows path issues | Shell script format | Use cross-platform syntax |
# Skip all hooks (use sparingly!)
git commit --no-verify -m "emergency: bypass hooks"
# Skip only pre-commit (keeps commit-msg)
HUSKY=0 git commit -m "fix: urgent hotfix"