AGENT SKILL

dry-refactoring

Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor clones using extract function, module, constant, or base class strategies.

License 许可
MIT
最近更新
2026-07-20
Stars
★ 0
Forks
0

01 前言 Front Matter

name
dry-refactoring
description
Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor clones using extract function, module, constant, or base class strategies.

03 SKILL.md 正文

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@4.0.5 --reporters ai <path>

See the jscpd skill for full option reference.

Workflow

  1. Run jscpd with --reporters ai on the target path
  2. Parse each clone line to identify the two duplicated locations (file + line range)
  3. Read both code fragments from the source files
  4. Understand what the duplicated code does
  5. Design a refactoring: extract a shared function, class, module, or constant
  6. Apply the refactoring — update both locations and all other usages
  7. Re-run jscpd to confirm the clone is eliminated
  8. Repeat for remaining clones, highest-impact first

Refactoring Strategies

Strategy When
Extract function Same logic repeated with different inputs
Extract constant Same literal values repeated
Extract base class Parallel class hierarchies with shared behaviour
Extract module Shared utilities across multiple modules
Template method Same algorithm structure, different steps

04 同仓库更多 Skills