dry-refactoring
하는 일
중복 코드를 찾아 하나의 공용 버전으로 합치는 단계별 방법을 설명합니다. 반복되는 로직의 기준을 하나로 유지하려는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓개발자가 같은 코드가 여러 곳에 붙어 있는 것을 발견하고 이를 합치려 할 때.
- ✓팀이 빠른 복사-붙여넣기 수정 후 중복을 제거하려 할 때.
- ✓개발자가 실제 중복과 비슷해 보이기만 하는 코드를 구분해야 할 때.
스킬 링크
https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이 프로젝트에서 복사해 붙여 넣은 코드를 찾아서, 가장 심한 반복을 공용 함수로 합쳐 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 먼저 중복 탐지 도구를 실행한 뒤, 완전히 같은 복사본을 먼저 고치고 나서 비슷한 복사본을 살피도록 AI에게 안내합니다. 함수나 상수를 분리하는 방법 같은 전략을 사용합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
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 --reporters ai <path>
In codebases that mix related formats (e.g. JavaScript and TypeScript), add --cross-formats so clones spanning both are detected too:
npx jscpd --reporters ai --cross-formats "js-ts" <path>
On larger codebases, add --summary to get a refactoring-hotspot overview alongside the clone list — top files and folders with a dup% column showing how much of each file is duplicated:
npx jscpd --reporters ai --summary <path>
The default scan reports only exact copies, and those are the ones to refactor first: an exact clone is almost always a real copy-paste. Two more passes find copies that were edited after pasting. They are noisier: they ignore names, values or a few statements on purpose, so they also surface blocks that merely look alike (models and DTOs, config tables, test setup, generated code, shared idioms). Run them only after the exact clones are dealt with, one family at a time, with tight settings, and treat what they report as leads to read rather than defects to fix:
# Type-2: renamed copies (other variable names, other constants), reported as "(renamed)".
# Raise --min-tokens: with identifiers ignored, a short block is mostly placeholders.
npx jscpd --reporters ai --ignore-identifiers --min-tokens 70 <path>
# Type-3: near-miss copies (one or two edited lines, or JS/TS/Python functions with the same structure),
# reported as "[~0.91 gap]" and "[~0.85 ast]". Widen only if the tight run finds nothing.
npx jscpd --reporters ai --max-gap-lines 1 --similarity <path>
See the jscpd skill for full option reference, including cross-format group syntax, the clone-kind suffixes and how to read the summary.
Workflow
- Run jscpd with
--reporters aion the target path (add--summaryon larger codebases to pick a starting point: files with highdup%and high token counts pay off most) - Parse each clone line to identify the two duplicated locations (file + line range) and its kind: no suffix is an exact copy,
(renamed)differs only in names or values,[~N gap]has a few edited lines in the middle,[~N ast]is a function pair with the same structure - Read both code fragments from the source files
- Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
- Triage renamed and similar clones before touching them. Skip the pair, and say so, when any of these holds: the two sides do different things despite the same shape (a
switchover different enums, two reducers with unrelated semantics); the sameness is intentional boilerplate (models, DTOs, config, route tables, test fixtures); the code is generated; a shared abstraction would need a vague name likeprocessData; or the pair is under about 10 lines. Only a pair that would let you delete code and give the extraction a precise name goes on to the next step - Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
- Apply the refactoring — update both locations and all other usages
- Re-run jscpd with the same flags to confirm the clone is eliminated and the
dup%of the touched files went down; a clone that was(renamed)will not show in a default run, so check with--ignore-identifiersagain - Repeat for remaining clones, highest-impact first: exact clones, then renamed, then similar. Report the skipped candidates separately from the refactored ones, with the reason, so nobody mistakes a normalized run's count for real duplication
Refactoring Strategies
Extract function — when the duplicate is a block of logic:
// Before: same block in two places
// After: shared function called from both places
Extract module/utility — when the duplicate spans multiple files in different domains:
// Move shared logic to a shared utility file and import it
Extract constant or config — when the duplicate is repeated data or configuration.
Template/base class — when the duplicate is structural (e.g., repeated class shape).
Parameterize — for (renamed) clones. The two sides are the same algorithm over different names or values, so the things that
자주 묻는 질문
완전히 같은 복사본을 먼저 고치는 이유는 무엇인가요?
완전히 같은 복사본은 거의 항상 실제 중복이므로, 시작하기에 가장 안전한 지점입니다.
비슷한 복사본은 항상 중복인가요?
아니요. 스킬은 비슷한 코드가 모델, 테스트 설정, 생성된 코드일 수 있어 겉보기에만 비슷할 수 있다고 경고합니다.
중복을 찾는 도구는 무엇인가요?
jscpd 중복 탐지기를 사용합니다.
상세 정보
작성자의 원본 설명
Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor exact, renamed and near-miss clones using extract function, parameterize, module, constant, or base class strategies, starting from the hotspots the summary ranks.
repo: kucherenko/jscpd
인기도
- GitHub 스타
- 6.5k
- 순위
- #14190
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
code-migration
6.5k에이전트가 테스트를 먼저 작성하고 원본과 비교하며, 코드를 다른 언어나 프레임워크로 함수 단위로 옮기도록 돕습니다.
codebase-refactoring
6.5k에이전트가 중복 코드를 고치고, 쓰이지 않는 코드를 제거하며, 가장 복잡한 파일을 단순하게 만들어 프로젝트 상태를 개선하도록 돕습니다. 이 순서대로 진행합니다.
compare-codebases
6.5k에이전트가 두 코드 폴더를 언어와 상관없이 함수 단위로 비교해, 서로 일치하는 함수와 빠진 함수를 찾도록 돕습니다.
jscpd
6.5k에이전트가 완전 복사, 이름만 바뀐 복사, 비슷한 복사 형태로 된 중복 코드를 찾고 그 비율을 측정하도록 돕습니다.