MCP HubMCP Hub
스킬 목록으로 돌아가기

refactoring-patterns

proffesor-for-testing
업데이트됨 Today
334 조회
267
56
267
GitHub에서 보기
기타refactoringcode-qualitytechnical-debtmaintainabilityclean-code

정보

이 Claude Skill은 기존 동작을 보존하면서 코드 구조를 개선하기 위해 안전한 리팩터링 패턴을 적용합니다. 이는 테스트 주도 접근법을 통해 코드를 정리하고 기술 부채를 줄이며 유지보수성을 향상시키도록 설계되었습니다. 본 스킬은 코드 변환 과정에서 신뢰성을 보장하기 위해 지속적인 테스트와 함께 작고 점진적인 변경을 강조합니다.

빠른 설치

Claude Code

추천
기본
npx skills add proffesor-for-testing/agentic-qe
플러그인 명령대체
/plugin add https://github.com/proffesor-for-testing/agentic-qe
Git 클론대체
git clone https://github.com/proffesor-for-testing/agentic-qe.git ~/.claude/skills/refactoring-patterns

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

Refactoring Patterns

<default_to_action> When refactoring:

  1. ENSURE tests pass (never refactor without tests)
  2. MAKE small change (one refactoring at a time)
  3. RUN tests (must stay green)
  4. COMMIT (save progress)
  5. REPEAT

Safe Refactoring Cycle:

npm test               # Green ✅
# Make ONE small change
npm test               # Still green ✅
git commit -m "refactor: extract calculateTotal"
# Repeat

Code Smells → Refactoring:

SmellRefactoring
Long method (>20 lines)Extract Method
Large classExtract Class
Long parameter list (>3)Introduce Parameter Object
Duplicated codeExtract Method/Class
Complex conditionalDecompose Conditional
Magic numbersNamed Constants
Nested loopsReplace Loop with Pipeline

NEVER REFACTOR:

  • Without tests (write tests first)
  • When deadline is tomorrow
  • Code you don't understand
  • Code that works and won't be touched </default_to_action>

Quick Reference Card

Common Refactorings

PatternBeforeAfter
Extract Method50-line function5 small functions
Extract ClassClass doing 5 things5 single-purpose classes
Parameter Objectfn(a,b,c,d,e,f)fn(options)
Replace Conditionalif (type === 'a') {...}Polymorphism
PipelineNested loops.filter().map().reduce()

The Rule of Three

  1. First time → Just do it
  2. Second time → Wince and duplicate
  3. Third time → Refactor

Key Patterns

Extract Method

// Before: Long method
function processOrder(order) {
  // 50 lines of validation, calculation, saving, emailing...
}

// After: Clear responsibilities
function processOrder(order) {
  validateOrder(order);
  const pricing = calculatePricing(order);
  const saved = saveOrder(order, pricing);
  sendConfirmationEmail(saved);
  return saved;
}

Replace Loop with Pipeline

// Before
let results = [];
for (let item of items) {
  if (item.inStock) {
    results.push(item.name.toUpperCase());
  }
}

// After
const results = items
  .filter(item => item.inStock)
  .map(item => item.name.toUpperCase());

Decompose Conditional

// Before
if (order.total > 1000 && customer.isPremium && allInStock(order)) {
  return 'FREE_SHIPPING';
}

// After
function isEligibleForFreeShipping(order, customer) {
  return isLargeOrder(order) &&
         isPremiumCustomer(customer) &&
         allInStock(order);
}

Refactoring Anti-Patterns

❌ Anti-PatternProblem✅ Better
Without testsNo safety netWrite tests first
Big bangRewrite everythingSmall incremental steps
For perfectionEndless tweakingGood enough, move on
Premature abstractionPattern not clear yetWait for Rule of Three
During feature workMixed changesSeparate commits

Agent Integration

// Detect code smells
const smells = await Task("Detect Code Smells", {
  source: 'src/services/',
  patterns: ['long-method', 'large-class', 'duplicate-code']
}, "qe-quality-analyzer");

// Safe refactoring with test verification
await Task("Verify Refactoring", {
  beforeCommit: 'abc123',
  afterCommit: 'def456',
  expectSameBehavior: true
}, "qe-test-executor");

Agent Coordination Hints

Memory Namespace

aqe/refactoring/
├── smells/*          - Detected code smells
├── suggestions/*     - Refactoring recommendations
├── verifications/*   - Behavior preservation checks
└── history/*         - Refactoring log

Fleet Coordination

const refactoringFleet = await FleetManager.coordinate({
  strategy: 'refactoring',
  agents: [
    'qe-quality-analyzer',   // Identify targets
    'qe-test-generator',     // Add safety tests
    'qe-test-executor',      // Verify behavior
    'qe-test-refactorer'     // TDD refactor phase
  ],
  topology: 'sequential'
});

Related Skills


Remember

Refactoring is NOT:

  • Adding features
  • Fixing bugs
  • Performance optimization
  • Rewriting from scratch

Refactoring IS:

  • Improving structure
  • Making code clearer
  • Reducing complexity
  • Removing duplication
  • Without changing behavior

Always have tests. Always take small steps. Always keep tests green.

GitHub 저장소

proffesor-for-testing/agentic-qe
경로: .claude/skills/refactoring-patterns
agenticqeagenticsfoundationagentsquality-engineering

연관 스킬

code-review-quality

기타

This skill conducts automated code reviews focused on quality, testability, and maintainability, prioritizing critical feedback like bugs and security issues. It's designed for use during code reviews, when providing feedback, or when establishing review practices. The tool categorizes feedback by severity and emphasizes asking questions over issuing commands.

스킬 보기

tdd-london-chicago

기타

This Claude Skill helps developers apply both London (mock-based) and Chicago (state-based) TDD approaches when practicing test-driven development. It guides you to choose the appropriate style based on your context—using Chicago for domain logic and London for code with external dependencies. The skill follows the red-green-refactor cycle and works with specialized testing agents to generate, implement, and refactor tests.

스킬 보기

content-collections

메타

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

스킬 보기

polymarket

메타

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

스킬 보기