setup-pre-commit

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

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/Fatih0234/mattpocock-skills-pi --skill setup-pre-commit-fatih0234
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/Fatih0234/mattpocock-skills-pi/tree/main/skills/misc/setup-pre-commit
Command: npx skills add https://github.com/Fatih0234/mattpocock-skills-pi --skill setup-pre-commit-fatih0234

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up pre-commit hooks is repetitive and error-prone: you need to install Husky, configure lint-staged, create a Prettier config, and hook in typecheck and test scripts. 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 (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 every commit to be formatted and verified. Run this Skill to install Husky, wire up lint-staged with Prettier, and add typecheck/test gates in one pass. ## Quick Start Set up pre-commit hooks in this repo with Husky, lint-staged, Prettier, and my typecheck and test scripts.

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, lint-staged, and prettier as devDependencies, then run npx husky init to create the .husky directory. Add a .husky/pre-commit file that runs lint-staged, typecheck, and test scripts so every commit is verified automatically.

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

Create a .lintstagedrc file mapping file patterns to commands, such as {"*": "prettier --ignore-unknown --write"}. The --ignore-unknown flag skips files Prettier cannot parse, like images, so lint-staged 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 like .husky/pre-commit. You can write plain commands such as npx lint-staged directly, and Husky executes them in the correct Git hook context.

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 matching command in the pre-commit hook and install steps.

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

If the repository lacks a typecheck or test script, omit those lines from the .husky/pre-commit file and inform the user. The hook will still run lint-staged for formatting, and the missing checks can be added once the scripts exist.