SkillHub GitHub

Skills mattpocock/skills

setup-pre-commit

Use it when
you want every commit in a JavaScript or TypeScript repo formatted, type-checked and tested first
It does
installs Husky, lint-staged and Prettier, and writes a pre-commit hook that formats staged files, then runs your type check and tests
You get
a .husky/pre-commit hook, a lint-staged config, a Prettier config if you had none, and a commit adding them
Works with
npm, pnpm, Yarn or Bun, whichever lockfile it finds

TLDR

Husky runs scripts on git events, and lint-staged runs a command on just the files you staged. The agent picks your package manager from the lockfile, installs the three tools as dev dependencies and initializes Husky. The hook it writes formats staged files with Prettier, skipping files Prettier can't read such as images, then runs your typecheck and test scripts over the whole project. If package.json has no typecheck or test script, it leaves that line out and tells you. An existing Prettier config is kept; otherwise it adds one with common defaults. It ends by committing the new files, which runs the new hook once and shows it works.

Summarizes the skill at 5beb35b.

npx skills add https://github.com/mattpocock/skills --skill setup-pre-commit
Installs
373,523 on skills.sh, Sep 21, 2026
Repo stars
266,454 mattpocock/skills
First seen
Feb 13, 2026 on skills.sh
Weekly installs
26.8K
+34% over 8 weeks · week to Sep 21
Weekly values
Week toInstalls
Aug 320,084
Aug 1022,024
Aug 1719,043
Aug 2428,983
Aug 3132,011
Sep 731,492
Sep 1428,713
Sep 2126,821
Category

Test-first work, implementation from specs, git hygiene and scope control.

Everything for building software: planning, coding, debugging, design, frameworks, cloud, agents and skills.

Type

One-time configuration or scaffolding of a project, account or tool.

Effect

Its own steps create or change files, git state or local tools.

Needs

Instructions only. Works in any agent that supports skills.

Publisher

Everyone else. Unverified vendor claims default to community.

Topics
Stack

SKILL.md

From mattpocock/skills at 5beb35b. Checked daily, last changed Oct 20, 2026.

Frontmatter
name: setup-pre-commit
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.

Setup Pre-Commit Hooks

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

Steps

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.

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier
3. Initialize Husky
npx husky init

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

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.

5. Create .lintstagedrc
{
  "*": "prettier --ignore-unknown --write"
}
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"
}
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
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.

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