mcpskills.net
SkillsMCPsAgentsPrompts
mcpskills.net — A curated directory of AI agent Skills and MCP servers
TermsPrivacy
← Back to Skills
Misc

Setup Pre-Commit

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo.

by Matt PocockRepository →Source →

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).

2. Install dependencies

Install as devDependencies: husky lint-staged prettier

3. Initialize Husky

npx husky init

4. Create .husky/pre-commit

npx lint-staged
npm run typecheck
npm run test

5. Create .lintstagedrc

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

6. Create .prettierrc (if missing)

{
  "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

8. Commit

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