setup-pre-commit

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

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/AO-HyS/aohys.com --skill setup-pre-commit-ao-hys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/AO-HyS/aohys.com/tree/main/.agents/skills/setup-pre-commit
Command: npx skills add https://github.com/AO-HyS/aohys.com --skill setup-pre-commit-ao-hys

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up commit-time quality checks is repetitive and error-prone: developers must install Husky, configure lint-staged, create Prettier configs, and remember to run typechecks and tests before every commit. This Skill automates the entire setup so every commit is automatically formatted, type-checked, and tested. ## Core Features & Use Cases - Husky Hook Setup: Installs Husky, initializes the .husky/ directory, and creates a pre-commit hook that runs lint-staged, typecheck, and tests. - lint-staged + Prettier Configuration: Creates .lintstagedrc to run Prettier on staged files and generates a sensible .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 consistent formatting and type safety enforced on every commit. Run this Skill to install and configure the full pre-commit pipeline, then verify it with a smoke-test commit. ## 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 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 validated automatically.

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

Use lint-staged with a .lintstagedrc file mapping "*" to "prettier --ignore-unknown --write". The pre-commit hook runs npx lint-staged, which applies Prettier only to files staged in Git, keeping commits fast.

Does Husky work with pnpm, yarn, or bun?▼

Yes, Husky works with any package manager. Detect the package manager from lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb) and adapt the hook commands accordingly, replacing npm with the detected tool in the pre-commit script.

Why does my Husky pre-commit hook not run after setup?▼

Common causes include a missing prepare script in package.json (it must be "husky"), a non-executable .husky/pre-commit file, or Husky not being initialized. Run npx husky init and verify the hook file exists and is executable.

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

If package.json lacks typecheck or test scripts, 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 scripts can be added later.