// Use when asked about code quality or duplication. Runs jscpd analysis for quantitative metrics and TDD refactoring plans. Triggers: "duplicate code", "code quality", "find clones", "copy-paste detection". If thinking "manual review is fine" - automate instead. NOTE: For "refactor" or "technical debt" → use this skill FIRST to identify targets, THEN use incremental-refactoring to implement changes.
| name | duplicate-code-detector |
| description | Use when asked about code quality or duplication. Runs jscpd analysis for quantitative metrics and TDD refactoring plans. Triggers: "duplicate code", "code quality", "find clones", "copy-paste detection". If thinking "manual review is fine" - automate instead. NOTE: For "refactor" or "technical debt" → use this skill FIRST to identify targets, THEN use incremental-refactoring to implement changes. |
Core principle: Systematic automated detection > manual subjective review
This skill is for DETECTION (finding duplicates). For IMPLEMENTATION (refactoring them), use incremental-refactoring afterward.
Sequential workflow:
duplicate-code-detector → Find and prioritize duplicatesincremental-refactoring → Implement changes with metricsIf user says "refactor technical debt" → Start here to identify targets, then hand off to incremental-refactoring.
TodoWrite: Create 5 items (1 per workflow step)
which jscpd || npm install -g jscpd
If unavailable: inform user, note manual analysis limitations.
jscpd docs: https://github.com/kucherenko/jscpd
jscpd --min-lines 5 --reporters json,console /path/to/code
For top 3-5 duplicate groups, dispatch with:
Analyze duplicate in File A (lines X-Y) vs File B (lines M-N).
Propose extraction (function/class/module), estimate impact.
Prioritize by: lines duplicated → instances → complexity
## Priority 1: [Name] (X lines, Y instances)
1. Write test for current behavior
2. Extract [function/class/module]
3. Replace duplicates
4. Verify tests pass
**Metrics:** X% duplication (Y lines, Z clone groups)
**Top 3 Priorities:** [list]
**Refactoring Plan:** [TDD steps]
Start with Priority 1?
Before marking complete:
| Thought | Reality |
|---|---|
| "Manual review is faster" | Misses 70% of duplicates |
| "I can spot patterns by eye" | Subjective, no metrics |
| "Let me read a few files first" | Run jscpd first, analyze after |