Files
2nd/10_Wiki/Topics/Architecture/Automated Refactoring Tools.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

4.9 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-automated-refactoring-tools Automated Refactoring Tools 10_Wiki/Topics verified self
Refactoring Tools
IDE Refactoring
Codemod Tools
none A 0.9 applied
refactoring
tooling
ast
codemod
2026-05-10 pending
language framework
typescript ts-morph,jscodeshift,comby,ast-grep

Automated Refactoring Tools

매 한 줄

"매 AST-level 의 transform — 매 sed 의 X, 매 syntax-aware 의 mass-edit". 매 IDE refactor (Rename · Extract) 의 80년대 Smalltalk 의 root, 2026 의 LLM-augmented codemod (Claude Opus 4.7 + ast-grep) 의 mainstream.

매 핵심

매 3 tier 의 tool

  • IDE-builtin: IntelliJ · VS Code · Rider — 매 single-file 의 dominant.
  • Codemod: jscodeshift · ts-morph · comby · ast-grep — 매 cross-cutting mass change.
  • LLM-driven: Claude Code · Cursor · GitHub Copilot Workspace — 매 semantic-aware 의 modernization.

매 refactor 종류

  • Rename (symbol-aware).
  • Extract function/variable/component.
  • Inline.
  • Move (file/module).
  • Change signature.
  • Convert (e.g. var → const, function → arrow).

매 응용

  1. 매 framework migration (Vue 2 → Vue 3, React class → hook).
  2. API breaking change 의 fan-out fix.
  3. Code style 의 mechanical enforcement.

💻 패턴

ts-morph: rename + add property

import { Project } from "ts-morph";

const project = new Project({ tsConfigFilePath: "tsconfig.json" });

for (const sf of project.getSourceFiles()) {
  for (const cls of sf.getClasses()) {
    if (cls.getName()?.endsWith("Service")) {
      cls.rename(cls.getName()!.replace(/Service$/, "Manager"));
      cls.addProperty({ name: "createdAt", type: "Date", initializer: "new Date()" });
    }
  }
}

await project.save();

ast-grep: pattern → rewrite (yaml rule)

id: useEffect-cleanup
language: tsx
rule:
  pattern: useEffect(() => { $$$BODY }, $DEPS)
fix: |
  useEffect(() => {
    $$$BODY
    return () => { /* cleanup */ };
  }, $DEPS)
ast-grep scan -r useEffect-cleanup.yml --update-all

jscodeshift: Vue Options → Composition API

export default function transformer(file, api) {
  const j = api.jscodeshift;
  const root = j(file.source);

  root.find(j.ObjectExpression)
    .filter(p => p.node.properties.some(pr => pr.key?.name === "data"))
    .forEach(path => {
      // emit setup() function with refs
      // ...
    });

  return root.toSource();
}
jscodeshift -t vue-comp-api.js src/
comby 'console.log(:[args])' 'logger.debug(:[args])' .ts -i

LLM codemod (Claude Opus 4.7) — semantic-aware

import anthropic

client = anthropic.Anthropic()
SYSTEM = "You convert React class components to functional + hooks. Preserve behavior."

with open("UserCard.tsx") as f:
    src = f.read()

resp = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=4096,
    system=SYSTEM,
    messages=[{"role": "user", "content": src}],
)
print(resp.content[0].text)
$method$($args$) { $body$ }
→ Constraints: method matches ".*Async$"
→ Replace with: async $method$($args$) { $body$ }

매 결정 기준

상황 Tool
매 single-file rename in IDE IDE builtin
TS-only · type-aware ts-morph
TS/JS · less type-aware · faster jscodeshift
Multi-language · structural comby · ast-grep
매 semantic refactor · framework migration LLM codemod
Mass mechanical regex-safe sed/perl (드물게)

기본값: TypeScript 의 ts-morph, polyglot 의 ast-grep, 매 semantic 의 LLM.

🔗 Graph

🤖 LLM 활용

언제: 매 semantic refactor (class→hook, callback→async/await), 매 deterministic rule 의 hard 의 case. 언제 X: 매 mechanical rename 의 case — IDE 가 cheaper · safer. LLM 의 hallucination risk 의 require code review.

안티패턴

  • Regex-only refactor: 매 string match 의 false positive (comment · string literal).
  • Test 없음 refactor: 매 mass codemod 의 test suite 의 gate 의 require.
  • PR 의 single huge codemod: 매 review 의 X — file-by-file commit 의 split.
  • LLM output 의 blind merge: 매 type-check + test 의 gate 의 mandatory.

🧪 검증 / 중복

  • Verified (ts-morph docs, Meta jscodeshift, comby.dev, ast-grep.github.io, Anthropic Claude API docs).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — 3-tier taxonomy + ts-morph/ast-grep/comby/LLM examples