Skill Tracer
Skills › Skills For Real Engineers › setup-pre-commit

setup-pre-commit

skill · 91 lines · MIT · skills/misc/setup-pre-commit/SKILL.md

The facts

Its description

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.

The description the agent reads to decide when to use it.

From its settingsline 3

When it starts

The agent would pick this skill when someone asks to add commit-time automation to the current repo — pre-commit hooks, Husky, lint-staged, or running Prettier/typecheck/tests before each commit. It is a one-shot setup task for a JavaScript/TypeScript repo, not a conversation about design or review.

Things a person might say (the model's guesses)

  • “Set up pre-commit hooks in this repo”
  • “Can you add Husky and lint-staged so staged files get formatted on commit?”
  • “I want typechecking and tests to run before every commit”

A model's summary of when it is used.

A model's reading

Licence

MIT, from LICENSE

The terms its author shares it under, which let it be shown here.

From the repositorylicence text
Other files in this skill (1) Close

The text

Open on GitHub
1---
2name: setup-pre-commit
3description: Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.
4---
5
6# Setup Pre-Commit Hooks
7

Setup Pre-Commit Hooks

Raw lines 1 to 7
8## What This Sets Up
9
10- **Husky** pre-commit hook
11- **lint-staged** running Prettier on all staged files
12- **Prettier** config (if missing)
13- **typecheck** and **test** scripts in the pre-commit hook

What This Sets Up

  • Husky pre-commit hook
  • lint-staged running Prettier on all staged files
  • Prettier config (if missing)
  • typecheck and test scripts in the pre-commit hook
Raw lines 8 to 14
17### 1. Detect package manager
19Check for `package-lock.json` (npm), `pnpm-lock.yaml` (pnpm), `yarn.lock` (yarn), `bun.lockb` (bun). Use whichever is present. Default to npm if unclear.

1. Detect package manager

Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. Default to npm if unclear.

Raw lines 17 to 20
21### 2. Install dependencies
23Install as devDependencies:
25```
26husky lint-staged prettier
27```

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier
Raw lines 21 to 28
29### 3. Initialize Husky
31```bash
32npx husky init
33```
35This creates `.husky/` dir and adds `prepare: "husky"` to package.json.

3. Initialize Husky

npx husky init

This creates .husky/ dir and adds prepare: "husky" to package.json.

Raw lines 29 to 36
37### 4. Create `.husky/pre-commit`
39Write this file (no shebang needed for Husky v9+):
41```
42npx lint-staged
43npm run typecheck
44npm run test
45```
47**Adapt**: Replace `npm` with detected package manager. If repo has no `typecheck` or `test` script in package.json, omit those lines and tell the user.

4. Create .husky/pre-commit

Write this file (no shebang needed for Husky v9+):

npx lint-staged
npm run typecheck
npm run test

Adapt: Replace npm with detected package manager. If repo has no typecheck or test script in package.json, omit those lines and tell the user.

Raw lines 37 to 48
49### 5. Create `.lintstagedrc`
51```json
53 "*": "prettier --ignore-unknown --write"
55```

5. Create .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}
Raw lines 49 to 56
57### 6. Create `.prettierrc` (if missing)
59Only create if no Prettier config exists. Use these defaults:
61```json
63 "useTabs": false,
64 "tabWidth": 2,
65 "printWidth": 80,
66 "singleQuote": false,
67 "trailingComma": "es5",
68 "semi": true,
69 "arrowParens": "always"
71```

6. Create .prettierrc (if missing)

Only create if no Prettier config exists. Use these defaults:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}
Raw lines 57 to 72
73### 7. Verify
75- [ ] `.husky/pre-commit` exists and is executable
76- [ ] `.lintstagedrc` exists
77- [ ] `prepare` script in package.json is `"husky"`
78- [ ] `prettier` config exists
79- [ ] Run `npx lint-staged` to verify it works

7. Verify

  • [ ] .husky/pre-commit exists and is executable
  • [ ] .lintstagedrc exists
  • [ ] prepare script in package.json is "husky"
  • [ ] prettier config exists
  • [ ] Run npx lint-staged to verify it works
Raw lines 73 to 80
81### 8. Commit
83Stage all changed/created files and commit with message: `Add pre-commit hooks (husky + lint-staged + prettier)`
85This will run through the new pre-commit hooks: a good smoke test that everything works.

8. Commit

Stage all changed/created files and commit with message: Add pre-commit hooks (husky + lint-staged + prettier)

This will run through the new pre-commit hooks: a good smoke test that everything works.

Raw lines 81 to 86
87## Notes
89- Husky v9+ doesn't need shebangs in hook files
90- `prettier --ignore-unknown` skips files Prettier can't parse (images, etc.)
91- The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests

Notes

  • Husky v9+ doesn't need shebangs in hook files
  • prettier --ignore-unknown skips files Prettier can't parse (images, etc.)
  • The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests
Raw lines 87 to 91

From mattpocock/skills at 4ae2317, 2026-10-31. Skills read by DeepSeek V4.1 Flash on 2026-11-04. Summary and techniques by Claude Opus 5.5 on 2026-11-06.