codebase-refactoring
Fungsinya
Ini adalah rencana pembersihan yang terpandu untuk seluruh proyek, mencakup kode berulang, kode yang tidak dipakai, dan berkas yang terlalu kompleks. Ini untuk pengembang yang ingin mengurangi beban pemeliharaan.
Kapan dipakai
- βSaat sebuah tim meminta pembersihan atau pelunasan utang teknis dalam proyek.
- βSaat seorang pengembang ingin tahu bagian basis kode mana yang paling perlu dikerjakan lebih dulu.
- βSaat sebuah tim ingin mengukur skor kesehatan proyek sebelum dan sesudah pembersihan.
Link skill
https://github.com/kucherenko/jscpd/blob/master/skills/codebase-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
βBersihkan proyek ini. Mulai dari masalah terbesar dan tunjukkan skor kesehatannya setelahnya.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menjalankan alat analisis kode untuk memeringkat masalah, lalu memandu AI memperbaiki duplikasi, kode mati, dan berkas kompleks, serta mengukur ulang skornya di akhir.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
codebase-refactoring
A guided pass over a codebase's three biggest maintenance costs β duplicated code, dead code, and complexity β using jscpd to find each and a strategy to fix it. Use this skill when asked to "clean up", "improve", "refactor" or "pay down tech debt in" a codebase, rather than to fix one specific bug.
Start here: measure, then prioritize
npx jscpd --health --reporters ai <path>
health 74 B (duplication 75, dead-code 72, complexity 76; 93 code lines)
The health score is a weighted mix of three sub-scores, each a share of the
code lines β high is good, 100 is clean. The lowest of the three names where
the codebase actually hurts most; if it isn't the order below, do that
dimension first instead. n/a on a dimension (e.g. dead code n/a) means
jscpd could not measure it β dead-code detection needs JavaScript,
TypeScript or Python to be a real share of the code β skip that step rather
than treating it as clean.
For the full picture behind that score β largest duplicated formats, most
complex files, largest dead-code findings, all in one screen β run npx jscpd --dashboard instead. Its console output (the default) is the only
reporter with that per-file detail; --reporters ai on --dashboard prints
the same one-line summary shown above, not the breakdown, so don't reach for
it expecting more than the score. Use --reporters json on --dashboard if
you need the detail in a parseable form.
The three passes below are otherwise independent and safe to run in any order; duplication β dead code β complexity is the default because fixing duplication first means step 2 isn't wasting effort tracing call sites that a later extract-function pass will move anyway, and clearing dead code before step 3 means the files ranked for simplification are ones actually worth simplifying, not ones about to be deleted.
Step 1 β Duplicated code
npx jscpd --reporters ai --summary <path>
Find and read each clone, decide whether it is a real copy worth merging, and apply the matching refactoring strategy (extract function, parameterize, extract a shared module or constant, or a base class/template for structural duplication). Full guided workflow, triage rules for renamed/near-miss clones, and worked examples per clone kind:
β dry-refactoring β run this now, then
come back here for steps 2 and 3. Its own --summary hotspot ranking is the
same one the health score's duplication dimension reads from, so a file it
flags as a duplication hotspot is the same file that dragged the score down.
Step 2 β Dead code
npx jscpd --dead-code --reporters ai <path>
basta dead code report β 18 findings across 30 files (22.1% of 272 lines)
Confidence is 0-100; anything below 90 has a listed reason it may be wrong. Verify a finding before deleting the code.
unused-file typescript/src/legacy-export.ts:1:1 confidence=95 typescript/src/legacy-export.ts is never imported and is not an entry point
unused-export typescript/src/invoice.ts:21:17 confidence=85 exported function `renderReceipt` is never imported
unused-symbol typescript/src/invoice.ts:29:10 confidence=90 function `describeTotal` is never used in typescript/src/invoice.ts
unused-import typescript/src/invoice.ts:2:10 confidence=100 `roundToCents` is imported but never used
This is a graph traversal from the project's entry points (package.json
main/bin/exports/scripts, pyproject.toml scripts, framework
conventions, or --entry <glob>), not a reference count β a helper whose
only caller is itself dead is reported too, so deleting one finding can make
another true that wasn't reported yet. Covers JavaScript, TypeScript, JSX,
TSX, Vue, Svelte, Astro and Python.
The four categories, and what to do with each
| Category | Meaning | Usual fix |
|---|---|---|
unused-file |
Never imported anywhere, not an entry point | Delete the file |
unused-export |
Exported, but no other file imports it | Delete it, or drop the export keyword if something in the same file still uses it |
unused-symbol |
A module-private declaration nothing in its own file references | Delete it |
unused-import |
Imported but never referenced in the file | Delete the import line |
Workflow
- Run with
--reporters ai(add--dead-code-categoriesto focus on one category,--include-testsif test-only usage shouldn't count as "used", `--i
Pertanyaan umum
Bagaimana skill memutuskan apa yang diperbaiki lebih dulu?
Skill memakai skor kesehatan yang mencakup duplikasi, kode mati, dan kompleksitas, lalu mulai dari yang skornya paling rendah.
Apakah ini bekerja untuk setiap bahasa?
Deteksi kode mati memerlukan JavaScript, TypeScript, atau Python sebagai bagian besar dari kodenya.
Apakah ini memperbaiki bug?
Ini menargetkan masalah pemeliharaan, bukan bug tertentu.
Detail
Deskripsi asli dari pembuat
Three-part workflow to improve overall codebase health with jscpd β find and fix duplicated code, find and remove or refactor dead code, then find and simplify the largest/most complex files. Starts from --dashboard/--health to prioritize and ends by re-measuring the score.
repo: kucherenko/jscpd
Popularitas
- Bintang GitHub
- 6.5k
- Peringkat
- #14188
- 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.
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.
dry-refactoring
6.5kMembantu agent Anda menghapus kode yang disalin-tempel dari proyek dengan menggabungkan blok yang berulang menjadi fungsi bersama, dimulai dari pengulangan terbesar.
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.