Agent skill

refactoring-patterns

Systematic code refactoring guide with design patterns. Use when refactoring spaghetti code, applying Strategy pattern to conditional branches, extracting functions by SRP, or replacing magic numbers with named constants.

Stars 88
Forks 14

Install this agent skill to your Project

npx add-skill https://github.com/revfactory/claude-code-harness/tree/main/experiments/results/case-003/harness/.claude/skills/refactoring-patterns

SKILL.md

Refactoring Patterns

리팩토링 워크플로우

1. 분석

  • 원본 코드의 입출력 동작을 완전히 이해
  • 매직 넘버, 중복 코드, 긴 조건 분기 식별
  • 각 코드 블록의 책임 파악

2. 설계

  • 매직 넘버 -> 명명된 상수 (constants.js)
  • 조건 분기(if/else, switch) -> 전략 패턴 (pricingStrategies.js)
  • 하나의 큰 함수 -> SRP 기반 단일 책임 함수 분리
  • 팩토리 함수로 전략 객체 생성

3. 구현

  • 상수 정의 파일 분리
  • 전략 클래스 구현 (base + 구체 전략)
  • 오케스트레이터 함수에서 전략 호출
  • SRP 함수 분리:
    • calculateLineItem() - 단일 항목 계산
    • applyDiscount() - 할인 적용
    • calculateTax() - 세금 계산
    • applyBulkDiscount() - 대량 할인
    • updateHistory() - 이력 갱신
    • calculateOrder() - 오케스트레이터

4. 테스트

  • 원본 vs 리팩토링 동일성 테스트 (동일 입력 -> 동일 출력)
  • 각 전략별 단위 테스트
  • 경계값 테스트 (수량 50, 51, 100, 101)
  • 엣지 케이스 (빈 배열, 할인 0%, 세금 0%)

상세 코드 패턴은 references/patterns.md 참조.

Expand your agent's capabilities with these related and highly-rated skills.

revfactory/claude-code-harness

interpreter-design

Programming language interpreter design and implementation guide. Use when the user requests building an interpreter, parser, lexer, or language implementation — including Pratt parsing, AST evaluation, scope chains, and closures.

88 14
Explore
revfactory/claude-code-harness

express-api-design

Express.js REST API design and implementation guide. Use when implementing REST API endpoints, creating Express routes, or setting up API project structure with MVC pattern.

88 14
Explore
revfactory/claude-code-harness

query-engine-design

SQL query engine design and implementation guide. Use when the user requests building a SQL engine, query parser, query planner, or query executor — including in-memory storage, SQL parsing, and query optimization.

88 14
Explore
revfactory/claude-code-harness

api-documentation

Write accurate and complete library API documentation. Use when creating API docs, README files, or function reference documentation. Ensures all signatures, parameters, return types, and examples are precise.

88 14
Explore
revfactory/claude-code-harness

async-debugging

Analyze and fix race conditions and concurrency bugs in async code. Use when debugging async bugs, fixing race conditions, resolving concurrency issues, or when shared state is accessed by multiple async operations.

88 14
Explore
revfactory/claude-code-harness

reactive-spreadsheet-design

리액티브 스프레드시트 엔진 설계 가이드. 셀 수식 파싱, 의존성 그래프(DAG), 증분 재계산, 내장 함수 구현 시 사용한다.

88 14
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results