setup-pre-commit

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

Updated Apr 28, 2026
One-click install
npx skills add https://github.com/GregM1991/skills --skill setup-pre-commit-gregm1991
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/GregM1991/skills/tree/main/skills/vendor/mattpocock/setup-pre-commit
Command: npx skills add https://github.com/GregM1991/skills --skill setup-pre-commit-gregm1991

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually setting up pre-commit hooks involves coordinating Husky, lint-staged, and Prettier configuration files, which is error-prone and easy to misconfigure. This Skill automates the entire setup so every commit is automatically formatted, type-checked, and tested. ## Core Features & Use Cases - Husky Hook Setup: Initializes Husky and creates a .husky/pre-commit hook that runs lint-staged, typecheck, and tests. - lint-staged + Prettier: Creates a .lintstagedrc that formats all staged files with Prettier, plus a default .prettierrc 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 every commit to be auto-formatted and verified. Run this Skill to install the tooling, write the config files, and commit the setup through the new hooks as a smoke test. ## Quick Start Set up Husky pre-commit hooks with 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 with lint-staged?▼

Install husky, lint-staged, and prettier as devDependencies, run npx husky init, then create a .husky/pre-commit file that runs npx lint-staged. Add a .lintstagedrc mapping files to prettier --write so staged files are formatted on each commit.

How to run Prettier only on staged files before commit?▼

Use lint-staged with a .lintstagedrc containing {"*": "prettier --ignore-unknown --write"}. The --ignore-unknown flag skips files Prettier cannot parse, such as images, so only supported staged files get formatted.

Does Husky v9 need a shebang in hook files?▼

No, Husky v9 and later do not require shebang lines in hook files like .husky/pre-commit. You can write the commands directly, such as npx lint-staged followed by your typecheck and test scripts.

Can I use Husky with pnpm, yarn, or bun instead of npm?▼

Yes, Husky works with any package manager. Detect the package manager from lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb) and replace npm with the appropriate command in the pre-commit hook and install steps.

What if my project has no typecheck or test script?▼

If package.json lacks a typecheck or test script, omit those lines from the .husky/pre-commit file and keep only the lint-staged step. Adding commands for missing scripts would cause every commit to fail.