跳到正文
cccskills
免费在 GitHub 公开

setup-pre-commit

Set up checks that run before each commit using Husky, lint-staged, and Prettier. Format staged files, run existing type-check and test scripts, then verify and commit the configuration.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

在当前仓库设置 Husky pre-commit hooks,集成 lint-staged (Prettier)、类型检查和测试。适用于用户想添加 pre-commit hooks、设置 Husky、配置 lint-staged,或在提交时运行格式化、类型检查和测试时。

查看安装方法

适用场景

  • Adding automated checks before commits
  • Formatting staged files with Prettier
  • Running type checks and tests before committing
  • Setting up and verifying Husky hooks

包含的文件(2)

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

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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

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

8. 提交

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

这会经过新的 pre-commit hooks,是一个不错的 smoke test。

备注

  • Husky v9+ 不需要 hook files 中的 shebangs
  • prettier --ignore-unknown 会跳过 Prettier 无法 parse 的 files(images 等)
  • pre-commit 先运行 lint-staged(快,只针对 staged files),再运行完整 typecheck 和 tests

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

ask-matt

免费

Find the right skill and sequence for your current development task, from shaping an idea to implementation, debugging, and review. The guide also explains when to prototype, prepare specifications, or move work into a fresh session.

中文简介正在准备中。当前显示英语简介。

  • Choose a workflow for turning an idea into working software
  • Find the starting point for a difficult bug investigation
  • Plan specifications and tickets for work across multiple sessions
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

Summarize the current conversation and launch a fresh background agent to continue the work. The handoff includes references to existing artifacts and suggested skills, removes sensitive information, and can emphasize the next session’s intended focus.

中文简介正在准备中。当前显示英语简介。

  • Continue ongoing work with a fresh agent
  • Focus the next session on a specific task
  • Hand off work using references to existing documents
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

Review changes from a chosen Git reference against both project coding standards and issue or specification requirements. Separate parallel reviews report rule violations, possible design problems, missing requirements, and changes beyond the intended scope.

中文简介正在准备中。当前显示英语简介。

  • Review a branch or pull request
  • Check changes since a specific commit
  • Find missing requirements or unintended scope
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

Design modules that expose simple interfaces while hiding substantial behavior. Use shared terms and principles to assess interface complexity, decide where behavior can be swapped, and organize code so callers and tests use the same interface.

中文简介正在准备中。当前显示英语简介。

  • Simplify a module interface
  • Review module structure during refactoring
  • Decide where behavior should be swappable
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

Diagnose difficult bugs and performance regressions by first building a repeatable check for the exact symptom. Minimize the reproduction, test ranked hypotheses, apply a fix, and verify the original scenario with regression tests where suitable.

中文简介正在准备中。当前显示英语简介。

  • Investigating persistent errors or incorrect output
  • Increasing reproduction rates for intermittent bugs
  • Measuring and diagnosing performance regressions
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

Clarify project terminology and the relationships between business concepts. Check definitions against concrete scenarios and code, update GLOSSARY.md as terms are agreed, and record significant design decisions with their trade-offs when the stated criteria are met.

中文简介正在准备中。当前显示英语简介。

  • Clarifying ambiguous project terminology
  • Creating or updating GLOSSARY.md
  • Checking concept boundaries against code and edge cases
vinvcn/mattpocock-skills-zh-CN51262026年10月20日 更新

查看 vinvcn 的全部技能

报告此技能的问题