setup-pre-commit

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up pre-commit hooks is error-prone: developers must install Husky, configure lint-staged, create Prettier configs, and remember to run type checks and tests before every commit. This Skill automates the entire setup so commits are consistently formatted and validated. ## 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 inherit a JavaScript repo with no commit-time checks. Run this Skill to add Husky pre-commit hooks that format staged files with Prettier and block commits that fail type checking or tests. ## 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 and prepare script. Create a .husky/pre-commit file that runs lint-staged, typecheck, and test commands.

How to run Prettier only on staged files before commit?

Use lint-staged with a .lintstagedrc file mapping file patterns to commands, such as {"*": "prettier --ignore-unknown --write"}. The pre-commit hook runs npx lint-staged so only staged files are formatted.

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 replace npm with the appropriate command in the pre-commit hook.

Why does my Husky pre-commit hook not run?

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?

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