Skip to content
Skills Library
Programming · Building & coding

qe-refactoring-patterns

/qe-refactoring-patterns

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

Repository
agentic-qe ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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

Original author description

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

How it works

  1. Quick Reference Card
  2. Key Patterns
  3. Refactoring Anti-Patterns
  4. Agent Integration
  5. Agent Coordination Hints
  6. Related Skills
  7. Remember
Original SKILL.md headings · 192 lines, 621 words
SKILL.md preview
---
inclusion: auto
name: qe-refactoring-patterns
description: "Apply safe refactoring patterns to improve code structure without changing behavior. Use when cleaning up code, reducing technical debt, or improving maintainability."
tags: [refactoring, code-quality, technical-debt, maintainability, clean-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:**
```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
</default_to_action>

## 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.**

Versions

The database has no other skills named qe-refactoring-patterns.

Identical content appears in 3 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 909795f217ca (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100refactoring
    Technical debt remediation and code restructuring workflow. Use when improving code structure, reducing complexity, extracting abstractions, or paying down accumulated technical debt.
  • 100moai-workflow-ddd
    Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation. Use when refactoring legacy code or reducing technical debt safely.
  • 100refactoring
    Use when improving the structure of code without changing its behavior. Covers safe refactoring sequences, characterization tests, and knowing when to stop. Trigger on "clean this up without changing behavior", "refactor this before i add the feature", "this module is impossible…
  • 100fai-refactor-skill
    Apply systematic code refactoring patterns with behavior preservation, test-driven validation, and complexity reduction. Use when improving code structure without changing external behavior.
  • 84refactor
    Systematic refactoring with behavior preservation. Use when improving existing code structure, reducing technical debt, or when code smells are detected.
  • 93code-quality
    two-stage review (spec compliance first, then code quality), refactoring, and quality improvement. Use when reviewing code, eliminating code smells, reducing technical debt, refactoring methods, running self-critique loops, or improving maintainability and readability.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.