setup-pre-commit

Configures Husky pre-commit hooks with lint-staged, Prettier, typecheck, and tests.

2|Updated Oct 16, 2021
One-click install
npx skills add https://github.com/pattobrien/dotfiles --skill setup-pre-commit-pattobrien
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/pattobrien/dotfiles/tree/main/.agents/skills/setup-pre-commit
Command: npx skills add https://github.com/pattobrien/dotfiles --skill setup-pre-commit-pattobrien

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires husky, lint-staged, prettier.

What problem does it solve? Manually wiring up commit-time checks in a JavaScript or TypeScript repo is repetitive and error-prone. This Skill automates the full setup of Husky pre-commit hooks so every commit is automatically formatted, type-checked, and tested before it lands. ## Core Features & Use Cases - Husky Hook Setup: Initializes Husky v9+ and creates a .husky/pre-commit hook that runs lint-staged, typecheck, and tests. - lint-staged + Prettier: Configures lint-staged to run Prettier on all staged files, with a sensible default .prettierrc created only if none exists. - Package Manager Detection: Detects npm, pnpm, yarn, or bun from lockfiles and adapts all commands accordingly. - Use Case: You just scaffolded a new TypeScript project and want consistent formatting and safety checks on every commit. Run this Skill to install dependencies, create the hook, verify the setup, and commit the result as a smoke test. ## Quick Start Set up pre-commit hooks with Husky, lint-staged, and Prettier in this repository.

Frequently Asked Questions about setup-pre-commit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Husky pre-commit hooks in a Node.js project?▼

Install husky as a devDependency, run npx husky init to create the .husky directory and prepare script, then write a .husky/pre-commit file containing the commands to run, such as npx lint-staged followed by typecheck and test scripts.

How to run Prettier on staged files with lint-staged?▼

Create a .lintstagedrc file mapping file patterns to commands, for example {"*": "prettier --ignore-unknown --write"}. The --ignore-unknown flag skips files Prettier cannot parse, such as images, so the hook never fails on binary assets.

Does Husky v9 need a shebang in hook files?▼

No, Husky v9 and later do not require shebang lines in hook files. You can write the .husky/pre-commit file as a plain list of commands, which simplifies hook maintenance compared to earlier Husky versions.

Can I use Husky and lint-staged with pnpm, yarn, or bun?▼

Yes, Husky and lint-staged work with any package manager. Detect the manager from the lockfile (pnpm-lock.yaml, yarn.lock, bun.lockb, or package-lock.json) and substitute the matching command in the pre-commit hook and install steps.

What if my package.json has no typecheck or test script?▼

Omit those lines from the .husky/pre-commit hook and inform the user. The hook should only reference scripts that actually exist in package.json, otherwise every commit will fail with a missing-script error.