dry-refactoring
Was er macht
Es bietet eine Schritt-für-Schritt-Methode, um doppelten Code zu finden und in eine gemeinsame Version zusammenzuführen. Es richtet sich an Entwickler, die für wiederholte Logik eine einzige Quelle der Wahrheit wollen.
Wann du ihn nutzt
- ✓Wenn ein Entwickler denselben Code an mehreren Stellen eingefügt findet und ihn zusammenführen will.
- ✓Wenn ein Team Duplikate nach einer schnellen Copy-Paste-Lösung entfernen will.
- ✓Wenn ein Entwickler unterscheiden muss, welche fast gleichen Kopien echte Duplikate sind und welche nur ähnlich aussehen.
Link zum Skill
https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Finde den kopierten Code in diesem Projekt und führe die schlimmsten Wiederholungen in gemeinsamen Funktionen zusammen.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die Fähigkeit führt zuerst einen Duplikatsucher aus und leitet den KI-Agenten dann an, exakte Kopien vor fast gleichen Kopien zu beheben. Dabei nutzt sie Strategien wie das Herauslösen einer Funktion oder einer Konstante.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen
Warum zuerst exakte Kopien beheben?
Eine exakte Kopie ist fast immer ein echtes Duplikat, daher ist das der sicherste Anfang.
Sind fast gleiche Kopien immer Duplikate?
Nein. Die Fähigkeit warnt, dass fast gleiche Kopien Modelle, Testaufbauten oder generierter Code sein können, die nur ähnlich aussehen.
Welches Werkzeug findet die Duplikate?
Sie nutzt den Duplikatsucher jscpd.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 6.5k
- Platz im Ranking
- #14190
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
code-migration
6.5kHilft deinem Agenten, Code Funktion für Funktion von einer Sprache oder einem Framework in ein anderes zu übertragen, mit Tests zuerst und dem Fortschritt im Vergleich zum Original.
codebase-refactoring
6.5kHilft deinem Agenten, die Qualität eines Codebestands zu verbessern, indem er doppelten Code behebt, toten Code entfernt und die komplexesten Dateien vereinfacht, in dieser Reihenfolge.
compare-codebases
6.5kHilft deinem Agenten, zwei Code-Ordner Funktion für Funktion zu vergleichen, auch über Sprachen hinweg, um zu sehen, welche Funktionen übereinstimmen und welche fehlen.
jscpd
6.5kHilft deinem Agenten, kopierten Code in einem Projekt zu finden, in exakter, umbenannter oder fast gleicher Form, und zu messen, wie viel Code doppelt vorkommt.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.