Setup pre commit
My personal SDLC toolbelt for AI coding agents — PRD to ship.
npx -y skills add helderberto/agent-skills --skill setup-pre-commitAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests. Use when user asks to "add pre-commit hooks", "setup husky", "setup pre-commit", "configure lint-staged", or wants commit-time formatting/typechecking/testing. Don't use for running linters manually or writing tests.
SKILL.md
2.9 KB, as published. Nobody here has run it
Setup Pre-Commit Hooks
What This Sets Up
- Husky pre-commit hook
- lint-staged running Prettier on all staged files
- Prettier config (if missing)
- typecheck and test scripts in the pre-commit hook (if they exist)
Workflow
-
Detect package manager from lock file:
package-lock.json(npm),pnpm-lock.yaml(pnpm),yarn.lock(yarn),bun.lockb(bun). Default to npm if unclear. -
Install devDependencies:
husky lint-staged prettier -
Initialize Husky:
npx husky initThis creates
.husky/dir and addsprepare: "husky"to package.json. -
Create
.husky/pre-commit(no shebang needed for Husky v9+):npx lint-staged <pm> run typecheck <pm> run testReplace
<pm>with detected package manager. If repo has notypecheckscript in package.json, omit that line and tell the user. Same fortest. -
Create
.lintstagedrc:{ "*": "prettier --ignore-unknown --write" } -
Create
.prettierrc(only if no Prettier config exists):{ "useTabs": false, "tabWidth": 2, "singleQuote": true, "trailingComma": "all" } -
Verify:
.husky/pre-commitexists and is executable.lintstagedrcexistspreparescript in package.json is"husky"- Prettier config exists
- Run
npx lint-stagedto confirm it works
-
Commit all changed/created files:
Add pre-commit hooks (husky + lint-staged + prettier)This runs through the new pre-commit hooks -- a good smoke test.
Rules
- Never overwrite existing Prettier config
- Never overwrite existing
.husky/pre-commitwithout asking user first - Always use detected package manager consistently
- Husky v9+ doesn't need shebangs in hook files
prettier --ignore-unknownskips files Prettier can't parse (images, etc.)- Pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests
Error Handling
- No
package.jsonfound -- report and stop - Existing
.husky/pre-commit-- ask user before overwriting husky initfails -- check node_modules exists, suggest running install firstnpx lint-stagedverification fails -- check Prettier is installed, check.lintstagedrcsyntax- No
typecheckortestscripts -- omit from hook, tell user which were skipped
See Also
- validate-code -- run lint/typecheck/tests manually
- commit -- create git commits following repo style