Aller au contenu
Skillpedia
Programmation générale6.5k · #14188

codebase-refactoring

Ce qu’il fait

Ce guide est un plan de nettoyage guidé pour un projet entier, couvrant le code répété, le code inutilisé et les fichiers trop complexes. Il s'adresse aux développeurs qui veulent réduire le travail de maintenance.

Quand l’utiliser

  • ✓Quand une équipe demande de nettoyer un projet ou de réduire sa dette technique.
  • ✓Quand un développeur veut savoir quelle partie d'une base de code demande le plus de travail en premier.
  • ✓Quand une équipe veut mesurer le score de santé du projet avant et après un nettoyage.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/kucherenko/jscpd/blob/master/skills/codebase-refactoring/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Nettoyez ce projet. Commencez par les plus gros problèmes, puis montrez-moi le score de santé après.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Le skill lance un outil d'analyse de code pour classer les problèmes, puis guide l'IA dans la correction des doublons, du code mort et des fichiers complexes, et mesure de nouveau le score à la fin.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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

  1. Run with --reporters ai (add --dead-code-categories to focus on one category, --include-tests if test-only usage shouldn't count as "used", `--i
Questions fréquentes

Comment décide-t-il de ce qu'il faut corriger en premier ?

Il utilise un score de santé couvrant la duplication, le code mort et la complexité, et commence par le plus faible.

Fonctionne-t-il pour tous les langages ?

La détection du code mort nécessite que JavaScript, TypeScript ou Python représentent une part importante du code.

Corrige-t-il des bogues ?

Il vise les problèmes de maintenance plutôt qu'un bogue précis.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
6.5k
Position au classement
#14188
Licence
MIT
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires