MCP HubMCP Hub
スキル一覧に戻る

refactoring-patterns

proffesor-for-testing
更新日 Yesterday
153 閲覧
99
21
99
GitHubで表示
その他refactoringcode-qualitytechnical-debtmaintainabilityclean-code

について

このClaudeスキルは、動作を保証しながらコード構造を改善する安全なリファクタリングパターンを適用し、技術的負債の削減と保守性の向上に最適です。開発者が小さなテスト検証済みの変更を行い、進捗を段階的にコミットする規律あるワークフローを実施します。主な機能には、安全なリファクタリングサイクルの保証、およびコードレビューと品質分析エージェントとの統合が含まれます。

クイックインストール

Claude Code

推奨
プラグインコマンド推奨
/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, using specialized agents for security, performance, and coverage analysis. It provides prioritized, context-driven feedback for pull requests or when establishing review practices. Developers should use it to get actionable, structured reviews that emphasize bugs and maintainability over subjective style preferences.

スキルを見る

tdd-london-chicago

その他

This skill helps developers apply London (mock-based) and Chicago (state-based) TDD approaches when practicing test-driven development. It guides style selection based on code type—using Chicago for domain logic and London for external dependencies—and provides structured support through the Red-Green-Refactor cycle. Key capabilities include generating, implementing, and refactoring tests with optimized agents for each phase.

スキルを見る

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.

スキルを見る

creating-opencode-plugins

メタ

This skill provides the structure and API specifications for creating OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It offers implementation patterns for JavaScript/TypeScript modules that intercept and extend the AI assistant's lifecycle. Use it when you need to build event-driven plugins for monitoring, custom handling, or extending OpenCode's capabilities.

スキルを見る