setup-pre-commit

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

20|2|Updated May 16, 2026
One-click install
npx skills add https://github.com/reddb-io/red-skills --skill setup-pre-commit-reddb-io
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/reddb-io/red-skills/tree/main/plugins/dev/skills/misc/setup-pre-commit
Command: npx skills add https://github.com/reddb-io/red-skills --skill setup-pre-commit-reddb-io

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Setting up commit-time code quality enforcement requires manually wiring together Husky, lint-staged, and Prettier, which is error-prone and easy to misconfigure across different package managers. ## Core Features & Use Cases - Husky Hook Setup: Initializes Husky and creates a .husky/pre-commit hook that runs lint-staged, typecheck, and tests. - Package Manager Detection: Detects npm, pnpm, yarn, or bun from lockfiles and adapts all commands accordingly. - Config Generation: Creates .lintstagedrc and a default .prettierrc only when no Prettier config exists. - Use Case: You just scaffolded a new Node.js project and want every commit to auto-format staged files and block commits that fail type checking or tests. ## 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 followed by your typecheck and test scripts. Add a .lintstagedrc mapping files to prettier --write.

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 work with pnpm, yarn, or bun?▼

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

Why does my Husky hook not run after setup?▼

Common causes are a missing prepare script in package.json (it must be "husky") or a non-executable .husky/pre-commit file. Husky v9 and later does not require shebang lines in hook files.

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.