setup-pre-commit
यह क्या करती है
यह Husky और lint-staged जोड़ती है, ताकि हर commit से पहले Prettier फ़ॉर्मेटिंग, type checks और टेस्ट चलें। यह उन डेवलपर्स के लिए है जो कोड commit होने से पहले ही समस्याएं पकड़ना चाहते हैं।
कब इस्तेमाल करें
- ✓जब आप चाहते हों कि हर commit पर कोड अपने-आप फ़ॉर्मेट हो।
- ✓जब आप चाहते हों कि commit होने से पहले type checks और टेस्ट चलें।
- ✓जब आप किसी प्रोजेक्ट के लिए Husky या lint-staged सेट कर रहे हों।
Skill का लिंक
https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“Pre-commit जांचें सेट कीजिए, ताकि हर commit से पहले मेरा कोड फ़ॉर्मेट और टेस्ट हो।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट टूल इंस्टॉल करता है, एक pre-commit फ़ाइल बनाता है जो फ़ॉर्मेटर, type check और टेस्ट चलाती है, और अगर फ़ॉर्मेटिंग कॉन्फ़िग नहीं है तो उसे जोड़ता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Setup Pre-Commit Hooks
What This Sets Up
- Husky pre-commit hook
- lint-staged running Prettier on all staged files
- Prettier config (if missing)
- typecheck and test scripts in the pre-commit hook
Steps
1. Detect package manager
Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. Default to npm if unclear.
2. Install dependencies
Install as devDependencies:
husky lint-staged prettier
3. Initialize Husky
npx husky init
This creates .husky/ dir and adds prepare: "husky" to package.json.
4. Create .husky/pre-commit
Write this file (no shebang needed for Husky v9+):
npx lint-staged
npm run typecheck
npm run test
Adapt: Replace npm with detected package manager. If repo has no typecheck or test script in package.json, omit those lines and tell the user.
5. Create .lintstagedrc
{
"*": "prettier --ignore-unknown --write"
}
6. Create .prettierrc (if missing)
Only create if no Prettier config exists. Use these defaults:
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
7. Verify
-
.husky/pre-commitexists and is executable -
.lintstagedrcexists -
preparescript in package.json is"husky" -
prettierconfig exists - Run
npx lint-stagedto verify it works
8. Commit
Stage all changed/created files and commit with message: Add pre-commit hooks (husky + lint-staged + prettier)
This will run through the new pre-commit hooks: a good smoke test that everything works.
Notes
- Husky v9+ doesn't need shebangs in hook files
prettier --ignore-unknownskips files Prettier can't parse (images, etc.)- The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests
अक्सर पूछे जाने वाले सवाल
यह hook क्या चलाता है?
यह staged फ़ाइलों पर Prettier के साथ lint-staged चलाता है, और अगर आपके प्रोजेक्ट में हों तो typecheck और test scripts भी चलाता है।
क्या यह मेरी Prettier सेटिंग्स बदल देगा?
नहीं। यह Prettier कॉन्फ़िग तभी बनाता है जब कोई मौजूद न हो।
क्या यह npm, pnpm और yarn के साथ काम करता है?
हां। यह पहचानता है कि आपका प्रोजेक्ट कौन-सा package manager इस्तेमाल करता है, और स्पष्ट न हो तो npm मानता है।
जानकारी
लेखक का मूल विवरण
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.
repo: mattpocock/skills
लोकप्रियता
- GitHub स्टार
- 310k
- रैंकिंग में स्थान
- #122
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
ask-matt
310kयह आपके एजेंट को कोडिंग स्किल के एक सेट का मार्गदर्शक बनाती है, जो आपकी स्थिति के लिए सही स्किल की ओर इशारा करता है, विचार से लेकर भेजे गए कोड तक।
code-review
310kयह आपके बदलावों को आपकी रिपॉज़िटरी के कोडिंग मानकों और मूल स्पेक के साथ जांचती है, merge से पहले दोनों समीक्षाएं साथ-साथ चलाकर।
domain-modeling
310kयह एक साझा प्रोजेक्ट शब्दावली बनाती है और मुख्य डिज़ाइन फ़ैसले दर्ज करती है, ताकि आपका कोड वही शब्द इस्तेमाल करे जो आपकी टीम करती है।
implement-spec
310kएक पूरे स्पेक और उसके टिकट्स को काम करने वाले कोड में बदलती है, टिकट्स को क्रम से संभालते हुए और उन्हें एक branch में जोड़ते हुए।
मिलती-जुलती skills
openclaw-update
394kयह आपके एजेंट को चल रहे OpenClaw Gateway को अपडेट करने में मदद करती है, इंस्टॉल के तरीके के अनुसार सही विधि चुनकर और सेशन बनाए रखकर।
diagnose-gateway
394kयह आपके एजेंट को सेटिंग्स, चैनल और पोर्ट जांचकर पता लगाने देती है कि OpenClaw Gateway क्यों फ़ेल हो रहा है, बिना कुछ बदले।
crabbox-apps
394kयह आपके एजेंट को किसी अस्थायी क्लाउड मशीन पर ऐप खोलने और चलाने देती है, फिर उसका व्यू आपके चैट के साइड पैनल में दिखाती है।