Skip to content
Skills Library
Programming · Automation

setup-pre-commit

/setup-pre-commit

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

Licence
MIT
Last repository change
20.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 20.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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

Original author description

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

How it works

  1. 这会配置什么
  2. 步骤
  3. 备注
Original SKILL.md headings · 88 lines, 224 words
SKILL.md preview
---
name: setup-pre-commit
description: 在当前仓库设置 Husky pre-commit hooks,集成 lint-staged (Prettier)、类型检查和测试。适用于用户想添加 pre-commit hooks、设置 Husky、配置 lint-staged,或在提交时运行格式化、类型检查和测试时。
---

# 设置 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

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

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

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

只有没有 Prettier config 时才创建。使用这些 defaults:

```json
{
  "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
Files in this package (2)
  • SKILL.md 2 KB
  • agents/openai.yaml 1 KB

Versions

RepositoryScoreLicence
This page · vinvcn/mattpocock-skills-zh-cn100MIT
mattpocock/skills100MIT
devcxl/mattpocock-skills-zh100MIT
wenwuzhidao/mattpocock-skills-zh100MIT
stevesolun/ctx100MIT
OutlineDriven/odin-codex-plugin100Apache-2.0

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version a5de22b26d35 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100git-hooks-husky-pre-commit-lintstaged
    Use this skill when enforcing linting, formatting, and unit tests before commit creation using Husky and lint-staged.
  • 100husky-and-hooks
    Use this skill when the user says 'git hooks', 'husky', 'lint-staged', 'pre-commit hook', 'commit-msg hook', 'commitlint', 'pre-push', 'lefthook', 'pre-commit framework', 'hooks not running', 'skip hooks', 'core.hooksPath'. Sets up and debugs client-side Git hooks: how hooks…
  • 90code-quality-tooling-edho-ferdian
    Set up the automated quality gate: Biome or ESLint+Prettier, Husky, lint-staged, and the equivalents for Python (Ruff), Go and Rust. Use for "setup ESLint", "setup Biome", "tambah Prettier", "pasang husky", "pre-commit hook", "lint-staged", "commit ke-block linter", "format on…
  • 100git-hooks-setup
    Use when setting up git hooks (pre-commit, commit-msg, pre-push) with husky or native hooks for linting, formatting, commit conventions, and secret scanning.
  • 100husky
    Runs scripts on Git hooks from a project's repository with Husky, so linters, formatters, tests and commit-message checks run before every commit or push. Use when a user asks to run linters before commit, validate commit messages, run tests before push, set up Git hooks for a…
  • 95dx-git-hooks-setup
    Use when setting up pre-commit and pre-push git hooks on any project (JS/TS, Go, shell scripts, or mixed), auditing whether an existing hook setup meets minimum requirements, or adding new mandatory checks to existing hooks. Triggered by "set up commit hooks", "add pre-commit…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.