refactoring-patterns
Systematic refactoring techniques, code smell elimination, pattern extraction, and legacy modernization
npx skills add cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Refactoring Patterns Systematically improve code without changing its behavior. ## The Refactoring Workflow 1. **Identify** a code smell or pain point 2. **Ensure** you have tests (write them first if not) 3. **Apply** one refactoring at a time 4. **Test** after each change (green = continue, red = revert) 5. **Commit** — small, focused, descriptive 6. **Repeat** ## Extract Method **When**: A method does multiple things or is too long. **How**: Find a cohesive block → extract to new method → call it. ```javascript // Before function processOrder(order) { const total = order.items.reduce((sum, i) => sum + i.price, 0); const tax = total * 0.08; const discount = order.coupon ? total * 0.1 : 0; return total + tax - discount; } // After function processOrder(order) { const subtotal = calculateSubtotal(order); const tax = calculateTax(subtotal); const discount = calculateDiscount(order, subtotal); return subtotal + tax - discount; } ``` ## Replace Conditional with Polymorphism **When**: Switch/if-else chains based on type grow too long. ```javascript // Before function calculateShipping(order) { if (order.type === 'standard') return order.weight * 0.5; if (order.type === 'express') ret
- The Refactoring Workflow
- Extract Method
- Replace Conditional with Polymorphism
- Legacy Code Strategy
- Common Refactorings
What does the refactoring-patterns skill do?
Systematic refactoring techniques, code smell elimination, pattern extraction, and legacy modernization
How do I install it?
Run `npx skills add cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From cosmicstack-labs/mercury-agent-skills, a repository with 364 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.