This automates the full pre-commit setup with Husky, lint-staged, and Prettier, and wires in typecheck and test scripts if they exist in your package.json. It detects whether you're using npm, pnpm, yarn, or bun, installs the right dependencies, and commits everything with a single message to trigger the hooks as a smoke test. The lint-staged config runs Prettier on all staged files, which is fast, then fires off your full type checking and tests. It's smart enough to skip creating a Prettier config if you already have one. Good for when you're past the prototype phase and want to stop broken code from sneaking into commits without manually setting up the whole Husky dance.

skills.sh installs
5.7K
GitHub stars
5.7K
last updated
Aug 21, 2026

Install

$ npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill setup-pre-commit --agent claude-code

Installs into .claude/skills of the current project.

Files

设置 Pre-Commit Hooks

这会配置什么

  • Husky pre-commit hook
  • lint-staged 对所有 staged files 运行 Prettier
  • Prettier config(如果缺失)
  • pre-commit hook 中的 typecheck 和 test scripts

步骤

1. 检测 package manager

检查 package-lock.json (npm)、pnpm-lock.yaml (pnpm)、yarn.lock (yarn)、bun.lockb (bun)。使用存在的那个。不清楚时默认 npm。

2. 安装依赖

作为 devDependencies 安装:

husky lint-staged prettier

3. 初始化 Husky

npx husky init

这会创建 .husky/ dir,并向 package.json 添加 prepare: "husky"。

4. 创建 .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,就省略对应行并告知用户。

5. 创建 .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}

6. 创建 .prettierrc(如果缺失)

只有没有 Prettier config 时才创建。使用这些 defaults:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. 验证

Sponsors

Details

Repository
github.com/vinvcn/mattpocock-skills-zh-cn
Categories
Frontend Development, Git & Pull Requests, Code Review & Quality
First seen
Jun 3, 2026

More from vinvcn/mattpocock-skills-zh-cn

All 39
1affaan-m avatarecc-guideaffaan-m/eccGuide users through ECC's current agents, skills, commands, hooks, rules, install profiles, and project onboarding by reading the live repository surface before5.5Kskills.sh installs
2web-infra-dev avatarandroid-device-automationweb-infra-dev/midscene-skillsVision-driven Android device automation using Midscene. Operates entirely from screenshots — no DOM or accessibility labels required. Can interact with all visi5.5Kskills.sh installs
3max-sixty avatarworktrunkmax-sixty/worktrunkGuidance for Worktrunk (the `wt` CLI) — git worktree management, hooks, and config. Load when editing .config/wt.toml or ~/.config/worktrunk/config.toml; adding5.5Kskills.sh installs
4ghostsecurity avatarghost-scan-codeghostsecurity/skillsGhost Security - SAST code scanner. Finds security vulnerabilities in source code by planning and executing targeted scans for issues like SQL injection, XSS, B5.5Kskills.sh installs
5wondelai avatarscorecard-marketingwondelai/skillsBuild quiz and assessment funnels that generate qualified leads at 30-50% conversion. Use when the user mentions "quiz funnel", "scorecard", "lead magnet", "sco5.5Kskills.sh installs
6affaan-m avataragent-sortaffaan-m/eccBuild an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel5.5Kskills.sh installs