Setup Pre-Commit Hooks

Setup Pre-Commit Hooks

Sets up Husky pre-commit hooks with lint-staged and Prettier, plus typecheck and test steps, adapting to the repo's package manager.

Skill files2 files

agents/

SKILL.md92 lines
1
---
2
name: setup-pre-commit
3
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.
4
---
5
6
# Setup Pre-Commit Hooks
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
14
15
## Steps
16
17
### 1. Detect package manager
18
19
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.
20
21
### 2. Install dependencies
22
23
Install as devDependencies:
24
25
```
26
husky lint-staged prettier
27
```
28
29
### 3. Initialize Husky
30
31
```bash
32
npx husky init
33
```
34
35
This creates `.husky/` dir and adds `prepare: "husky"` to package.json.
36
37
### 4. Create `.husky/pre-commit`
38
39
Write this file (no shebang needed for Husky v9+):
40
41
```
42
npx lint-staged
43
npm run typecheck
44
npm run test
45
```
46
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.
48
49
### 5. Create `.lintstagedrc`
50
51
```json
52
{
53
"*": "prettier --ignore-unknown --write"
54
}
55
```
56
57
### 6. Create `.prettierrc` (if missing)
58
59
Only create if no Prettier config exists. Use these defaults:
60
61
```json
62
{
63
"useTabs": false,
64
"tabWidth": 2,
65
"printWidth": 80,
66
"singleQuote": false,
67
"trailingComma": "es5",
68
"semi": true,
69
"arrowParens": "always"
70
}
71
```
72
73
### 7. Verify
74
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
80
81
### 8. Commit
82
83
Stage all changed/created files and commit with message: `Add pre-commit hooks (husky + lint-staged + prettier)`
84
85
This will run through the new pre-commit hooks: a good smoke test that everything works.
86
87
## Notes
88
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
92

© Matt Pocock · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…