MCP HubMCP Hub
返回技能列表

refactoring-patterns

proffesor-for-testing
更新于 Today
119 次查看
99
21
99
在 GitHub 上查看
其他refactoringcode-qualitytechnical-debtmaintainabilityclean-code

关于

This Claude Skill applies safe refactoring patterns to improve code structure while preserving behavior, ideal for reducing technical debt and enhancing maintainability. It enforces a disciplined workflow where developers make small, test-verified changes and commit progress incrementally. Key features include a guaranteed safe refactoring cycle and integration with code review and quality analysis agents.

快速安装

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

其他

这是一个专注于代码质量、可测试性和可维护性的上下文驱动代码审查技能。它能在审查代码、提供反馈或建立审查实践时,自动从质量、安全、性能和测试覆盖度等多维度进行分析。该技能通过优先级分类、提问式反馈和提供上下文建议,帮助开发者进行高效、有建设性的代码评审。

查看技能

tdd-london-chicago

其他

该Skill帮助开发者在测试驱动开发中选择伦敦学派(基于模拟)或芝加哥学派(基于状态)的测试风格。它能根据代码类型(领域逻辑或外部依赖)推荐合适的测试方法,并指导完整的“红-绿-重构”TDD周期。适用于实践TDD或为特定上下文选择测试策略的开发场景。

查看技能

content-collections

Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。

查看技能

creating-opencode-plugins

该Skill为开发者创建OpenCode插件提供指导,涵盖命令、文件、LSP等25+种事件类型。它详细说明了插件结构、事件API规范及JavaScript/TypeScript实现模式,帮助开发者构建事件驱动的模块。适用于需要拦截操作、扩展功能或自定义AI助手行为的插件开发场景。

查看技能