Skip to content
OpenSmartRoute
Skillv1.0.0

setup-pre-commit

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

by mattpocock(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from mattpocock/skills (skills/misc/setup-pre-commit/SKILL.md) via skills.sh. Install upstream with npx skills add mattpocock/skills --skill setup-pre-commit. Copyright stays with the author.

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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/mattpocock-skills-setup-pre-commit/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

mattpocock-skills-setup-pre-commit.ocm.jsonjson
{
  "ocm": "1",
  "id": "mattpocock-skills-setup-pre-commit",
  "kind": "skill",
  "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.",
  "publisher": "mattpocock",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "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."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/mattpocock/skills",
      "path": "skills/misc/setup-pre-commit/SKILL.md",
      "ref": "HEAD",
      "url": "https://www.skills.sh/mattpocock/skills/setup-pre-commit",
      "key": "mattpocock/skills/skills/misc/setup-pre-commit/SKILL.md"
    }
  },
  "instructions": "# Setup Pre-Commit Hooks\n\n## What This Sets Up\n\n- **Husky** pre-commit hook\n- **lint-staged** running Prettier on all staged files\n- **Prettier** config (if missing)\n- **typecheck** and **test** scripts in the pre-commit hook\n\n## Steps\n\n### 1. Detect package manager\n\nCheck for `package-lock.json` (npm), `pnpm-lock.yaml` (pnpm), `yarn.lock` (yarn), `bun.lockb` (bun). Use whichever is present. Default to npm if unclear.\n\n### 2. Install dependencies\n\nInstall as devDependencies:\n\n```\nhusky lint-staged prettier\n```\n\n### 3. Initialize Husky\n\n```bash\nnpx husky init\n```\n\nThis creates `.husky/` dir and",
  "cost": {
    "context_tokens": 493
  }
}

Fetch it by URL: GET /api/v1/registry/mattpocock-skills-setup-pre-commit/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.