Skip to content
Agentmart
Submit a tool

setup-pre-commit

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

Skill by WenWuZhiDao

IndexedMIT★ 29
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/wenwuzhidao-setup-pre-commit

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

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

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 26, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/setup-pre-commit

What's inside

Skill name
setup-pre-commit
Description
在当前仓库中设置 Husky pre-commit 钩子,配合 lint-staged(Prettier)、类型检查和测试。当用户想添加 pre-commit 钩子、设置 Husky、配置 lint-staged,或在提交时添加格式化/类型检查/测试时使用。
License
MIT
Instructions
88 lines in SKILL.md · view on GitHub

Files (2)

  • SKILL.md
  • openai.yaml · agents/

SKILL.md (first lines)

# 设置预提交钩子(Pre-Commit Hooks)

## 这会设置什么

- **Husky** 预提交钩子
- **lint-staged** 对所有暂存文件运行 Prettier
- **Prettier** 配置(如果缺失)
- 预提交钩子中的 **typecheck** 和 **test** 脚本

## 步骤

### 1. 检测包管理器

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

### 2. 安装依赖

作为 devDependencies 安装:

```
husky lint-staged prettier
```

### 3. 初始化 Husky

```bash
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`

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

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

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

```json
{
  "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)`

这会跑一遍新的预提交钩子 —— 是验证一切正常的良好冒烟测试。

## 注意事项

- Husky v9+ 的钩子文件不需要 shebang
- `prettier --ignore-unknown` 会跳过 Prettier 无法解析的文件(图片等)
- 预提交会先运行 lint-staged(快速,仅针对暂存文件),然后运行完整的类型检查和测试

From WenWuZhiDao/mattpocock-skills-zh, MIT.

More from WenWuZhiDao/mattpocock-skills-zh

Signals

Stars
29
Forks
5
Open issues
0
Last commit (this folder)
Jul 24, 2026 (3 months ago)
Last release
Aug 13, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from WenWuZhiDao

Cite this page

setup-pre-commit skill. Agent Mart. https://agentmart.dev/skills/wenwuzhidao-setup-pre-commit (last updated 2026-10-24)