Skip to content

Step-by-step Husky pre-commit setup that wires lint-staged, Prettier, typecheck, and tests into commits.

CCM score
66 of 100
skills.sh installs
5.8K
GitHub stars
6.2K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers detecting the package manager, installing husky, lint-staged, and prettier, and initializing the hook
  • Creates .husky/pre-commit, .lintstagedrc, and a default .prettierrc only when no Prettier config exists
  • Runs lint-staged on staged files first, then the full typecheck and test scripts, skipping any script the repo lacks
  • Designed for JavaScript repositories that want formatting and checks enforced at commit time

Install

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

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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. 验证

Details

Repository
github.com/vinvcn/mattpocock-skills-zh-cn
Categories
Git & Releases, Testing & QA, Code Review & Quality
First seen
Jun 3, 2026

Questions

What does the setup-pre-commit skill do?

It sets up Husky pre-commit hooks in the current repository, wired to lint-staged with Prettier, a typecheck script and a test script. It also creates a Prettier config if the project has none. The skill fits when you want formatting, typechecks and tests to run on every commit.

How do I install the setup-pre-commit skill?

Run npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill setup-pre-commit -y in your project. After that, the agent can install husky, lint-staged and prettier, run husky init, and write the pre-commit hook file.

Where does setup-pre-commit rank in its category?

It sits in the Git & Releases category on Claude Marketplaces and ranks in the top 50 there. Other skills in that category include triage, git-guardrails-claude-code, caveman-commit and pr.

What does the skill need before it runs?

The repository needs a package.json, and the skill detects the package manager from its lock file, using npm when unclear. If the package.json has no typecheck or test script, the skill leaves that line out and tells you.

More from vinvcn/mattpocock-skills-zh-cn

All 24

Similar to Setup Pre Commit

More Git & Releases