dry-refactoring

Refactor duplicated code detected by jscpd into shared functions, modules, or constants.

Updated Aug 3, 2026
One-click install
npx skills add https://github.com/Yvesdefaria/GymLab --skill dry-refactoring-yvesdefaria
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dry-refactoring
Source: https://github.com/Yvesdefaria/GymLab/tree/main/gymlab-app/.agents/skills/dry-refactoring
Command: npx skills add https://github.com/Yvesdefaria/GymLab --skill dry-refactoring-yvesdefaria

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jscpd.

What problem does it solve? Copy-paste duplication spreads across a codebase over time, making maintenance risky because every fix must be applied in multiple places. This Skill provides a guided workflow to systematically eliminate clones reported by jscpd and consolidate them into single, well-named abstractions. ## Core Features & Use Cases - Guided clone elimination: Parse jscpd AI-reporter output, read both duplicated fragments, design a refactoring, apply it to all call sites, and re-run jscpd to confirm the clone is gone. - Multiple refactoring strategies: Choose between extract function, extract module/utility, extract constant/config, or template/base class depending on the shape of the duplication. - Cross-format clone handling: Detect and consolidate clones spanning JavaScript and TypeScript files using jscpd's --cross-formats option, typically merging into the TypeScript implementation. - Use Case: After running jscpd on a React + TypeScript app, you find the same data-mapping logic copied in three components. Use this Skill to extract a shared utility, update all call sites, and verify the clone count drops to zero. ## Quick Start Run jscpd with the AI reporter on my src folder and refactor the reported duplications into shared functions, verifying each fix by re-running the scan.

Frequently Asked Questions about dry-refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove code duplication detected by jscpd?

Run jscpd with --reporters ai on the target path, parse each reported clone to locate both duplicated fragments, then extract a shared function, module, or constant. Update all call sites and re-run jscpd to confirm the clone is eliminated.

How to detect code clones across JavaScript and TypeScript files?

Use jscpd with the --cross-formats "js-ts" option so clones spanning both formats are detected. When found, consolidate into one implementation, usually the TypeScript version, and update imports rather than extracting a third shared copy.

Which refactoring strategy should I use for duplicated code?

Extract a function for duplicated logic blocks, a shared module or utility when duplication spans multiple domains, a constant for repeated data or configuration, and a template or base class for repeated structural shapes.

Why does jscpd report too many trivial clones?

Small default thresholds cause noise from trivial matches. Use --min-lines 10 to filter out insignificant duplications and focus on meaningful clones, starting with the highest line counts for the most impact.

What should I check after refactoring duplicated code?

Ensure all call sites are updated, not just the two locations reported by jscpd, and confirm tests still pass. Give the extracted abstraction a clear, descriptive name and re-run jscpd to verify the clone is gone.