setup-pre-commit

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

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/TrayMachi/dotfiles --skill setup-pre-commit-traymachi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/TrayMachi/dotfiles/tree/main/agents/skills/setup-pre-commit
Command: npx skills add https://github.com/TrayMachi/dotfiles --skill setup-pre-commit-traymachi

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Setting up pre-commit hooks manually involves juggling Husky initialization, lint-staged configuration, Prettier defaults, and package manager differences, which is error-prone and easy to get wrong. ## Core Features & Use Cases - Automated Husky Setup: Detects the package manager (npm, pnpm, yarn, bun), installs husky, lint-staged, and prettier, and runs husky init. - Commit-Time Quality Gates: Creates a .husky/pre-commit hook that runs lint-staged, typecheck, and tests before every commit. - Sensible Defaults: Generates .lintstagedrc and .prettierrc configs when missing, then verifies and commits the setup as a smoke test. - Use Case: You start a new TypeScript project and want every commit automatically formatted, type-checked, and tested without manually wiring up Husky and lint-staged. ## Quick Start Set up Husky pre-commit hooks with lint-staged, Prettier, typecheck, and tests 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 --ignore-unknown --write.

How to run Prettier 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 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 like .husky/pre-commit. You can write plain commands such as npx lint-staged directly in the file.

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

Yes, detect the package manager from the lockfile: package-lock.json for npm, pnpm-lock.yaml for pnpm, yarn.lock for yarn, or bun.lockb for bun. Adapt the hook commands to use the detected package manager.

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 hook and inform the user. The hook should only reference scripts that actually exist to avoid failing commits.