dry-refactoring
Fungsinya
Skill ini memberi metode langkah demi langkah untuk menemukan kode duplikat dan menggabungkannya menjadi satu versi bersama. Skill ini untuk pengembang yang ingin menyimpan satu sumber kebenaran untuk logika yang berulang.
Kapan dipakai
- βSaat seorang pengembang menemukan kode yang sama ditempel di beberapa tempat dan ingin menggabungkannya.
- βSaat sebuah tim ingin menghapus duplikat setelah perbaikan salin-tempel yang cepat.
- βSaat seorang pengembang perlu membedakan salinan hampir sama yang benar-benar duplikat dari yang hanya tampak mirip.
Link skill
https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βCari kode salin-tempel dalam proyek ini dan gabungkan pengulangan terburuk menjadi fungsi bersama.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menjalankan pencari duplikat terlebih dahulu, lalu memandu AI memperbaiki salinan yang persis sama sebelum melihat salinan yang hampir sama. Skill memakai strategi seperti mengekstrak fungsi atau konstanta.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Mengapa salinan yang persis sama diperbaiki dulu?
Salinan yang persis sama hampir selalu duplikat sungguhan, sehingga itu tempat paling aman untuk mulai.
Apakah salinan yang hampir sama selalu duplikat?
Tidak. Skill memperingatkan bahwa salinan yang hampir sama bisa berupa model, pengaturan tes, atau kode hasil generator yang hanya tampak mirip.
Alat apa yang menemukan duplikat?
Skill memakai pendeteksi duplikat jscpd.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 6.5k
- Peringkat
- #14190
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
code-migration
6.5kMembantu agent Anda memindahkan kode dari satu bahasa atau framework ke yang lain, satu fungsi setiap kali, dengan tes lebih dulu dan kemajuan diukur terhadap versi asli.
codebase-refactoring
6.5kMembantu agent Anda meningkatkan kesehatan basis kode dengan memperbaiki kode duplikat, menghapus kode mati, dan menyederhanakan berkas yang paling kompleks, sesuai urutan itu.
compare-codebases
6.5kMembantu agent Anda membandingkan dua folder kode fungsi demi fungsi, bahkan lintas bahasa, untuk melihat fungsi mana yang cocok dan mana yang hilang.
jscpd
6.5kMembantu agent Anda menemukan kode salin-tempel dalam proyek, dalam bentuk persis sama, diganti nama, atau hampir sama, dan mengukur seberapa banyak kode yang terduplikasi.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.