agentleFS
popsiclelmlmpopsiclelmlm/skills-cn/skills/misc/setup-pre-commit/SKILL.md

setup-pre-commit

Skill0 starsChanged 6 months agoMITView on GitHub

在当前 repo 中设置带 lint-staged(Prettier)、type checking 和 tests 的 Husky pre-commit hooks。当用户想添加 pre-commit hooks、设置 Husky、配置 lint-staged,或添加 commit-time formatting/typechecking/testing 时使用。

124 other projects use a version of this, 113 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use setup-ts-deep-modules, loop-me and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • liufeng1976Skill

    setup-ts-deep-modules

    Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.

    Also in 41 projects that use this

  • RoentekSkill

    loop-me

    Grill me about specs for the workflows I want to build, within this workspace.

    Also in 52 projects that use this

  • ryotaroh180105Skill

    claude-handoff

    Hand the current conversation off to a fresh background agent that picks up the work immediately.

    Also in 39 projects that use this

  • FabienDehopreSkill

    decision-mapping

    Turn a loose idea into a sequenced map of investigation tickets, then drive them to resolution one at a time.

    Also in 6 projects that use this

The file

Files
SKILL.md

Setup Pre-Commit Hooks

What This Sets Up

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

Steps

1. Detect package manager

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

2. Install dependencies

作为 devDependencies 安装:

husky lint-staged prettier

3. Initialize Husky

npx husky init

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

4. Create .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. Create .lintstagedrc

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

6. Create .prettierrc(如果缺失)

只有在不存在 Prettier config 时才创建。使用这些 defaults:

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

7. Verify

  • .husky/pre-commit 存在且可执行
  • .lintstagedrc 存在
  • package.json 中的 prepare script 是 "husky"
  • prettier config 存在
  • 运行 npx lint-staged 验证可用

8. Commit

Stage 所有 changed/created files,并用这个 message 提交:Add pre-commit hooks (husky + lint-staged + prettier)

这会跑过新的 pre-commit hooks,是确认一切可用的好 smoke test。

Notes

  • Husky v9+ 不需要在 hook files 中写 shebangs
  • prettier --ignore-unknown 会跳过 Prettier 无法解析的 files(images 等)
  • pre-commit 会先运行 lint-staged(快,只处理 staged-only),然后运行完整 typecheck 和 tests

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.