मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग6.5k · #14190

dry-refactoring

यह क्या करती है

यह दोहराया हुआ कोड खोजने और उसे एक साझा रूप में मिलाने का चरण-दर-चरण तरीका देती है। यह उन डेवलपर्स के लिए है जो दोहराए गए तर्क का एक ही स्रोत रखना चाहते हैं।

कब इस्तेमाल करें

  • ✓जब डेवलपर को एक ही कोड कई जगह चिपका हुआ मिले और उसे मिलाना हो।
  • ✓जब टीम जल्दबाज़ी के कॉपी-पेस्ट सुधार के बाद दोहराव हटाना चाहे।
  • ✓जब डेवलपर को पता करना हो कि कौन सी लगभग-नकल असली दोहराव हैं और कौन सी केवल मिलती-जुलती दिखती हैं।

Skill का लिंक

https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

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

  1. Run jscpd with --reporters ai on the target path (add --summary on larger codebases to pick a starting point: files with high dup% and high token counts pay off most)
  2. 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
  3. Read both code fragments from the source files
  4. Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
  5. 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 switch over 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 like processData; 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
  6. Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
  7. Apply the refactoring — update both locations and all other usages
  8. 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-identifiers again
  9. 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

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

code-migration

6.5k

आपके एजेंट को एक भाषा या फ़्रेमवर्क से दूसरे में कोड एक-एक फ़ंक्शन करके ले जाने में मदद करती है, पहले टेस्ट के साथ और मूल से तुलना करके प्रगति मापते हुए।

कोडिंगसामान्य कोडिंग

codebase-refactoring

6.5k

आपके एजेंट को किसी कोडबेस की सेहत सुधारने में मदद करती है: दोहराया कोड ठीक करके, बेकार कोड हटाकर और सबसे जटिल फ़ाइलों को सरल बनाकर, इसी क्रम में।

कोडिंगसामान्य कोडिंग

compare-codebases

6.5k

आपके एजेंट को दो कोड फ़ोल्डरों की तुलना फ़ंक्शन-दर-फ़ंक्शन करने में मदद करती है, भाषाएँ अलग होने पर भी, यह देखने के लिए कि कौन से फ़ंक्शन मेल खाते हैं और कौन से गायब हैं।

कोडिंगसामान्य कोडिंग

jscpd

6.5k

आपके एजेंट को प्रोजेक्ट में सटीक, नाम बदले हुए या लगभग-नकल वाले कॉपी-पेस्ट कोड खोजने में मदद करती है, और यह मापने में कि कितना कोड दोहराया गया है।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills