dry-refactoring
यह क्या करती है
यह दोहराया हुआ कोड खोजने और उसे एक साझा रूप में मिलाने का चरण-दर-चरण तरीका देती है। यह उन डेवलपर्स के लिए है जो दोहराए गए तर्क का एक ही स्रोत रखना चाहते हैं।
कब इस्तेमाल करें
- ✓जब डेवलपर को एक ही कोड कई जगह चिपका हुआ मिले और उसे मिलाना हो।
- ✓जब टीम जल्दबाज़ी के कॉपी-पेस्ट सुधार के बाद दोहराव हटाना चाहे।
- ✓जब डेवलपर को पता करना हो कि कौन सी लगभग-नकल असली दोहराव हैं और कौन सी केवल मिलती-जुलती दिखती हैं।
Skill का लिंक
https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“इस प्रोजेक्ट में कॉपी-पेस्ट किया हुआ कोड खोजिए और सबसे खराब दोहराव साझा फ़ंक्शन में मिलाइए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह स्किल पहले एक डुप्लिकेट खोजक चलाती है, फिर AI को पहले सटीक नकल ठीक करने और बाद में लगभग-नकल देखने का मार्गदर्शन देती है। यह फ़ंक्शन या स्थिरांक निकालने जैसी रणनीतियाँ इस्तेमाल करती है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
dry-refactoring
Guided workflow to eliminate copy-paste duplication in source code. Use after running jscpd to detect clones.
Prerequisites
First, run jscpd to identify duplications:
npx jscpd --reporters ai <path>
In codebases that mix related formats (e.g. JavaScript and TypeScript), add --cross-formats so clones spanning both are detected too:
npx jscpd --reporters ai --cross-formats "js-ts" <path>
On larger codebases, add --summary to get a refactoring-hotspot overview alongside the clone list — top files and folders with a dup% column showing how much of each file is duplicated:
npx jscpd --reporters ai --summary <path>
The default scan reports only exact copies, and those are the ones to refactor first: an exact clone is almost always a real copy-paste. Two more passes find copies that were edited after pasting. They are noisier: they ignore names, values or a few statements on purpose, so they also surface blocks that merely look alike (models and DTOs, config tables, test setup, generated code, shared idioms). Run them only after the exact clones are dealt with, one family at a time, with tight settings, and treat what they report as leads to read rather than defects to fix:
# Type-2: renamed copies (other variable names, other constants), reported as "(renamed)".
# Raise --min-tokens: with identifiers ignored, a short block is mostly placeholders.
npx jscpd --reporters ai --ignore-identifiers --min-tokens 70 <path>
# Type-3: near-miss copies (one or two edited lines, or JS/TS/Python functions with the same structure),
# reported as "[~0.91 gap]" and "[~0.85 ast]". Widen only if the tight run finds nothing.
npx jscpd --reporters ai --max-gap-lines 1 --similarity <path>
See the jscpd skill for full option reference, including cross-format group syntax, the clone-kind suffixes and how to read the summary.
Workflow
- Run jscpd with
--reporters aion the target path (add--summaryon larger codebases to pick a starting point: files with highdup%and high token counts pay off most) - Parse each clone line to identify the two duplicated locations (file + line range) and its kind: no suffix is an exact copy,
(renamed)differs only in names or values,[~N gap]has a few edited lines in the middle,[~N ast]is a function pair with the same structure - Read both code fragments from the source files
- Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
- Triage renamed and similar clones before touching them. Skip the pair, and say so, when any of these holds: the two sides do different things despite the same shape (a
switchover different enums, two reducers with unrelated semantics); the sameness is intentional boilerplate (models, DTOs, config, route tables, test fixtures); the code is generated; a shared abstraction would need a vague name likeprocessData; or the pair is under about 10 lines. Only a pair that would let you delete code and give the extraction a precise name goes on to the next step - Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
- Apply the refactoring — update both locations and all other usages
- Re-run jscpd with the same flags to confirm the clone is eliminated and the
dup%of the touched files went down; a clone that was(renamed)will not show in a default run, so check with--ignore-identifiersagain - Repeat for remaining clones, highest-impact first: exact clones, then renamed, then similar. Report the skipped candidates separately from the refactored ones, with the reason, so nobody mistakes a normalized run's count for real duplication
Refactoring Strategies
Extract function — when the duplicate is a block of logic:
// Before: same block in two places
// After: shared function called from both places
Extract module/utility — when the duplicate spans multiple files in different domains:
// Move shared logic to a shared utility file and import it
Extract constant or config — when the duplicate is repeated data or configuration.
Template/base class — when the duplicate is structural (e.g., repeated class shape).
Parameterize — for (renamed) clones. The two sides are the same algorithm over different names or values, so the things that
अक्सर पूछे जाने वाले सवाल
सटीक नकल पहले क्यों ठीक करें?
सटीक नकल लगभग हमेशा असली दोहराव होती है, इसलिए यह शुरू करने की सबसे सुरक्षित जगह है।
क्या लगभग-नकल हमेशा दोहराव होती है?
नहीं। स्किल चेताती है कि लगभग-नकल मॉडल, टेस्ट सेटअप या जनरेट किया कोड हो सकती है जो केवल मिलता-जुलता दिखता है।
दोहराव कौन सा टूल खोजता है?
यह jscpd डुप्लिकेट डिटेक्टर इस्तेमाल करती है।
जानकारी
लेखक का मूल विवरण
Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor exact, renamed and near-miss clones using extract function, parameterize, module, constant, or base class strategies, starting from the hotspots the summary ranks.
repo: kucherenko/jscpd
लोकप्रियता
- GitHub स्टार
- 6.5k
- रैंकिंग में स्थान
- #14190
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
code-migration
6.5kआपके एजेंट को एक भाषा या फ़्रेमवर्क से दूसरे में कोड एक-एक फ़ंक्शन करके ले जाने में मदद करती है, पहले टेस्ट के साथ और मूल से तुलना करके प्रगति मापते हुए।
codebase-refactoring
6.5kआपके एजेंट को किसी कोडबेस की सेहत सुधारने में मदद करती है: दोहराया कोड ठीक करके, बेकार कोड हटाकर और सबसे जटिल फ़ाइलों को सरल बनाकर, इसी क्रम में।
compare-codebases
6.5kआपके एजेंट को दो कोड फ़ोल्डरों की तुलना फ़ंक्शन-दर-फ़ंक्शन करने में मदद करती है, भाषाएँ अलग होने पर भी, यह देखने के लिए कि कौन से फ़ंक्शन मेल खाते हैं और कौन से गायब हैं।
jscpd
6.5kआपके एजेंट को प्रोजेक्ट में सटीक, नाम बदले हुए या लगभग-नकल वाले कॉपी-पेस्ट कोड खोजने में मदद करती है, और यह मापने में कि कितना कोड दोहराया गया है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।