| name | refactoring-patterns |
| description | Safe transformations — same behavior, better structure. |
| tier | core |
| applyTo | **/*refactor*,**/*extract*,**/*rename*,**/*inline* |
Refactoring Patterns Skill
Safe transformations — same behavior, better structure.
Golden Rule
Tests pass before AND after. Never refactor and add features in the same commit.
When to Refactor
| Trigger | Action |
|---|
| Feature is hard to add | Refactor first, then add feature |
| Same bug twice | Refactor to prevent recurrence |
| "I don't understand" | Refactor for clarity |
| Duplicate code | Extract and reuse |
| Long function (>30 lines) | Extract logical units |
When NOT to Refactor
- No tests + time pressure
- Code won't change again
- Right before release (deadline pressure)
- Should rewrite instead (>70% changes needed)
- Exploratory/prototype code
Core Refactoring Moves
Extract Function
When a block does one logical thing, give it a name.
() {
(!order..) ();
(!order.) ();
(order. < ) ();
taxRate = order. === ? : ;
tax = order. * taxRate;
discount = order.. ? : ;
finalTotal = order. + tax - (order. * discount);
finalTotal;
}
() {
(order);
tax = (order);
discount = (order);
order. + tax - discount;
}
(): {
(!order..) ();
(!order.) ();
(order. < ) ();
}
(): {
taxRate = order. === ? : ;
order. * taxRate;
}
(): {
order.. ? order. * : ;
}