setup-pre-commit

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

Updated Aug 5, 2026
One-click install
npx skills add https://github.com/pd-phuc/laravel-template --skill setup-pre-commit-pd-phuc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/pd-phuc/laravel-template/tree/main/.claude/skills/setup-pre-commit
Command: npx skills add https://github.com/pd-phuc/laravel-template --skill setup-pre-commit-pd-phuc

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up Git pre-commit hooks, staged-file formatting, and commit-time checks is repetitive and error-prone. This Skill automates the entire setup so every commit is automatically formatted, type-checked, and tested before it lands in the repository. ## 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: Adds a .lintstagedrc that runs Prettier on all staged files, plus a default .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 JavaScript/TypeScript project and want every commit auto-formatted and validated. Run this Skill once and the hooks, configs, and an initial smoke-test commit are done for you. ## Quick Start Set up pre-commit hooks with Husky, 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 in a JavaScript project?▼

Install husky, lint-staged, and prettier as devDependencies, then run npx husky init to create the .husky directory. Add a pre-commit hook file that runs lint-staged, typecheck, and test scripts, and configure lint-staged to run Prettier on staged files.

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

Use lint-staged with a .lintstagedrc config mapping files to prettier --ignore-unknown --write. The pre-commit hook runs npx lint-staged, which formats only the files included in the current commit rather than the whole codebase.

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 substitute the appropriate command in the hook file instead of npm.

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

Common causes include a missing prepare script set to husky in package.json, a non-executable hook file, or hooks installed before dependencies. Verify .husky/pre-commit exists and run npx lint-staged manually to confirm it works.

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

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