Skip to content
cccskills
FreePublished on GitHub

setup-pre-commit

在当前仓库中设置 Husky pre-commit 钩子,集成 lint-staged(Prettier)、类型检查和测试。当用户想要添加 pre-commit 钩子、设置 Husky、配置 lint-staged、或添加提交时的格式化/类型检查/测试时使用。

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md2.4 KB
  • agents/openai.yaml97 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

设置 Pre-Commit 钩子

将要设置的内容

  • Husky pre-commit 钩子
  • lint-staged 对所有暂存文件运行 Prettier
  • Prettier 配置(如果缺失)
  • typecheck 和 test 脚本在 pre-commit 钩子中运行

步骤

1. 检测包管理器

检查 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/ 目录并在 package.json 中添加 prepare: "husky"。

4. 创建 .husky/pre-commit

写入以下内容(Husky v9+ 不需要 shebang):

npx lint-staged
npm run typecheck
npm run test

适配:将 npm 替换为检测到的包管理器。如果仓库的 package.json 中没有 typecheck 或 test 脚本,则省略对应行并告知用户。

5. 创建 .lintstagedrc

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

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

仅当不存在 Prettier 配置时才创建。使用以下默认值:

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

7. 验证

  • .husky/pre-commit 存在且可执行
  • .lintstagedrc 存在
  • package.json 中的 prepare 脚本为 "husky"
  • prettier 配置存在
  • 运行 npx lint-staged 验证其是否正常工作

8. 提交

暂存所有更改/创建的文件,并使用消息提交:Add pre-commit hooks (husky + lint-staged + prettier)

这将触发新的 pre-commit 钩子执行:是一个很好的冒烟测试,验证一切正常。

注意事项

  • Husky v9+ 不需要在钩子文件中加 shebang
  • prettier --ignore-unknown 会跳过 Prettier 无法解析的文件(如图片等)
  • pre-commit 钩子先运行 lint-staged(快速,仅处理暂存文件),然后运行完整的 typecheck 和 test

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

询问哪个技能或流程适合你的情况。本仓库内技能的路由器。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

在单次长会话中协调子智能体并安排日程,持续推进一项长期目标。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

把当前对话交接给一个全新的后台 agent,让它立刻接手工作。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

从固定点(commit、branch、tag 或 merge-base)开始,沿两条轴线审查变更——规范(代码是否遵循仓库文档化的编码规范?)和规格(代码是否与原始 issue/PRD 的要求一致?)。两条审查线在并行子 agent 中运行,并以并排方式报告结果。当用户想审查一个分支、PR、进行中的变更,或要求"从 X 开始审查"时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

设计深度模块的共享词汇。当用户想要设计或改进模块的接口、寻找深化机会、决定 seam 的位置、让代码更可测试或更易被 AI 导航,或者其他 skill 需要深度模块词汇时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

针对棘手 bug 和性能回归的诊断循环。当用户说"诊断"/"调试这个",或报告某处崩溃/报错/不正常/缓慢时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

See all skills by devcxl

Report a problem with this skill