From mattpocock-skills
Sets up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests. Detects package manager (npm/pnpm/yarn/bun) for JS/TS repos needing commit-time linting/formatting/testing.
npx claudepluginhub vinvcn/mattpocock-skills-zh-cnThis skill uses the workspace's default tool permissions.
- **Husky** pre-commit hook
Sets up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Useful for adding commit-time formatting, linting, type checks, and testing.
Installs ecosystem-specific git pre-commit hooks for formatting, linting, type-checking, and tests: Husky+lint-staged (JS), pre-commit (Python/OCaml), lefthook (Go), cargo-husky (Rust).
Checks and configures pre-commit hooks against project standards for frontend, infrastructure, and Python projects. Detects type via package.json, pyproject.toml, or Terraform/Helm files; verifies hook versions.
Share bugs, ideas, or general feedback.
检查 package-lock.json (npm)、pnpm-lock.yaml (pnpm)、yarn.lock (yarn)、bun.lockb (bun)。使用存在的那个。不清楚时默认 npm。
作为 devDependencies 安装:
husky lint-staged prettier
npx husky init
这会创建 .husky/ dir,并向 package.json 添加 prepare: "husky"。
.husky/pre-commit写入这个文件(Husky v9+ 不需要 shebang):
npx lint-staged
npm run typecheck
npm run test
Adapt:把 npm 替换为检测到的 package manager。如果 repo 的 package.json 没有 typecheck 或 test script,就省略对应行并告知用户。
.lintstagedrc{
"*": "prettier --ignore-unknown --write"
}
.prettierrc (if missing)只有没有 Prettier config 时才创建。使用这些 defaults:
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
.husky/pre-commit 存在且可执行.lintstagedrc 存在prepare script 是 "husky"npx lint-staged 验证可用Stage 所有 changed/created files,并用 message 提交:Add pre-commit hooks (husky + lint-staged + prettier)
这会经过新的 pre-commit hooks,是一个不错的 smoke test。
prettier --ignore-unknown 会跳过 Prettier 无法 parse 的 files(images 等)