🎯

refactoring-patterns

🎯Skill

from proffesor-for-testing/agentic-qe

VibeIndex|
What it does

Applies systematic refactoring techniques to improve code structure, readability, and maintainability without altering existing functionality.

refactoring-patterns

Installation

Install skill:
npx skills add https://github.com/proffesor-for-testing/agentic-qe --skill refactoring-patterns
4
Last UpdatedJan 26, 2026

Skill Details

SKILL.md

"Apply safe refactoring patterns to improve code structure without changing behavior. Use when cleaning up code, reducing technical debt, or improving maintainability."

Overview

# Refactoring Patterns

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:

```bash

npm test # Green βœ…

# Make ONE small change

npm test # Still green βœ…

git commit -m "refactor: extract calculateTotal"

# Repeat

```

Code Smells β†’ Refactoring:

| Smell | Refactoring |

|-------|-------------|

| Long method (>20 lines) | Extract Method |

| Large class | Extract Class |

| Long parameter list (>3) | Introduce Parameter Object |

| Duplicated code | Extract Method/Class |

| Complex conditional | Decompose Conditional |

| Magic numbers | Named Constants |

| Nested loops | Replace 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

Quick Reference Card

Common Refactorings

| Pattern | Before | After |

|---------|--------|-------|

| Extract Method | 50-line function | 5 small functions |

| Extract Class | Class doing 5 things | 5 single-purpose classes |

| Parameter Object | fn(a,b,c,d,e,f) | fn(options) |

| Replace Conditional | if (type === 'a') {...} | Polymorphism |

| Pipeline | Nested 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

```javascript

// 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

```javascript

// 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

```javascript

// 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-Pattern | Problem | βœ… Better |

|-----------------|---------|-----------|

| Without tests | No safety net | Write tests first |

| Big bang | Rewrite everything | Small incremental steps |

| For perfection | Endless tweaking | Good enough, move on |

| Premature abstraction | Pattern not clear yet | Wait for Rule of Three |

| During feature work | Mixed changes | Separate commits |

---

Agent Integration

```typescript

// 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

```typescript

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

  • [tdd-london-chicago](../tdd-london-chicago/) - TDD refactor phase
  • [code-review-quality](../code-review-quality/) - Review refactored code
  • [xp-practices](../xp-practices/) - Collective ownership

---

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.

More from this repository10

🎯
n8n-security-testing🎯Skill

Automates security vulnerability scanning and penetration testing for n8n workflows, identifying potential risks and misconfigurations.

🎯
database-testing🎯Skill

Validates database schemas, tests data integrity, verifies migrations, checks transaction isolation, and measures query performance.

🎯
brutal-honesty-review🎯Skill

Delivers unvarnished technical criticism with surgical precision, combining expert-level BS detection and zero-tolerance for low-quality work.

🎯
n8n-expression-testing🎯Skill

n8n-expression-testing skill from proffesor-for-testing/agentic-qe

🎯
n8n-trigger-testing-strategies🎯Skill

Validates n8n workflow triggers by comprehensively testing webhook, schedule, polling, and event-driven mechanisms with robust payload and authentication checks.

🎯
n8n-integration-testing-patterns🎯Skill

Validates n8n integration connectivity, authentication flows, and error handling across external service APIs through comprehensive testing patterns.

🎯
six-thinking-hats🎯Skill

Applies Six Thinking Hats methodology to systematically analyze software testing challenges from multiple perspectives, enhancing decision-making and test strategy development.

🎯
risk-based-testing🎯Skill

Prioritizes testing efforts by systematically assessing and ranking risks based on probability and potential impact across software components.

🎯
shift-left-testing🎯Skill

Accelerates software quality by moving testing earlier in development, reducing defect costs through proactive validation, automated testing, and continuous improvement practices.

🎯
chaos-engineering-resilience🎯Skill

chaos-engineering-resilience skill from proffesor-for-testing/agentic-qe