← ClaudeAtlas

setup-pre-commitlisted

Set up Husky pre-commit hooks with lint-staged (Prettier or Biome), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, add commit-time formatting/typechecking/testing, or says "add pre-commit", "setup hooks for this repo", "wire up husky". Triggers on pre-commit, husky, lint-staged, prettier hook, biome hook, commit hook, setup hooks, format on commit.
ArieGoldkin/claude-forge · ★ 6 · Code & Development · score 71
Install: claude install-skill ArieGoldkin/claude-forge
# Setup Pre-Commit Hooks ## What This Sets Up - **Husky** pre-commit hook - **lint-staged** running a formatter on staged files - **Formatter config** — Prettier OR Biome (choose by ecosystem) - **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. Detect formatter preference Inspect existing config OR ask the user: - `biome.json` / `biome.jsonc` present → use Biome - `.prettierrc*` / `prettier.config.*` present → use Prettier - Neither → ask: **"Prettier (broader ecosystem) or Biome (faster, all-in-one)?"** ### 3. Install dependencies For **Prettier**: ``` husky lint-staged prettier ``` For **Biome**: ``` husky lint-staged @biomejs/biome ``` Use the detected package manager (`npm install -D`, `pnpm add -D`, `yarn add -D`, `bun add -D`). ### 4. Initialize Husky ```bash npx husky init ``` Creates `.husky/` and adds `prepare: "husky"` to `package.json`. ### 5. Create `.husky/pre-commit` No shebang needed for Husky v9+: ``` npx lint-staged npm run typecheck npm run test ``` **Adapt**: replace `npm` with the detected package manager. If the repo lacks a `typecheck` or `test` script in `package.json`, omit those lines and tell the user (don't silently fail-shut). ### 6. Create `.lintstagedrc` For **Prettier**: ```json { "*": "prettier --ignore-unknown --w