skills/arcadeai/refactoring/SKILL.md
Systematic refactoring with small-step discipline. Use when user says 'refactor', 'clean up', 'restructure', 'extract', 'rename', 'simplify', or mentions code smells. Enforces one change → test → commit cycle. For structural improvements, NOT style/formatting (use /lint). NOT for adding features or fixing bugs.
npx skillsauth add aiskillstore/marketplace refactoringInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Improve code structure without changing behavior. One small step at a time.
Iron Law: ONE REFACTORING → TEST → COMMIT. Never batch changes.
Answer IN ORDER. Stop at first match:
Code smells (common triggers):
Is this actually refactoring?
| User Intent | Action | | ------------------- | ----------------------------------------------- | | "Make this cleaner" | ✓ Refactoring | | "Add validation" | ✗ New behavior → tdd-enforcer | | "Fix this bug" | ✗ Bug fix → tdd-enforcer or systematic-debugger | | "Format this code" | ✗ Style → /lint |
If not refactoring: Explain and suggest correct approach.
Does the code have tests?
| Coverage | Action | | ---------------- | --------------------------------------------- | | Well-tested | Skip to Phase 3 | | Partial coverage | Add characterization tests for untested parts | | No tests | Add characterization tests first |
Capture current behavior before refactoring:
// Characterization test - captures ACTUAL behavior
it('processOrder returns current behavior', () => {
const result = processOrder({ items: [], user: null });
// Whatever it returns NOW is the expected value
expect(result).toEqual({ status: 'empty', total: 0 });
});
Purpose: Safety net, not specification. Test what the code DOES, not what it SHOULD do.
Iron Law: ONE refactoring at a time. Run tests after EVERY change.
Tier 1 - Always Safe (no behavior change possible):
| Smell | Refactoring | Example |
| -------------------- | -------------------- | -------------------------------------- |
| Unclear name | Rename | d → discountAmount |
| Long function | Extract Function | Pull 10 lines into calculateTax() |
| Unnecessary variable | Inline Variable | Remove temp = x; return temp; |
| Misplaced code | Move Function | Move validate() to Validator class |
// ❌ Before: unclear name
const d = price * 0.2;
// ✅ After: Rename
const discountAmount = price * 0.2;
Tier 2 - Safe with Tests (low risk if tests exist):
| Smell | Refactoring | Example |
| ------------------- | ------------------------- | ------------------------------------------------- |
| Repeated expression | Extract Variable | order.items.length > 0 → const hasItems = ... |
| Complex conditional | Decompose Conditional | Extract if branches to named functions |
| Nested conditionals | Guard Clauses | Early returns instead of deep nesting |
| Magic literal | Replace Magic Literal | 0.2 → VIP_DISCOUNT_RATE |
| Unused code | Remove Dead Code | Delete unreachable branches |
// ❌ Before: nested conditionals
function getDiscount(user) {
if (user) {
if (user.isVIP) {
return 0.2;
} else {
return 0.1;
}
}
return 0;
}
// ✅ After: Guard Clauses
function getDiscount(user) {
if (!user) return 0;
if (user.isVIP) return 0.2;
return 0.1;
}
Tier 3 - Requires Care (higher risk, break into smaller steps):
| Smell | Refactoring | Caution | | -------------------------- | ------------------------------ | ------------------------------------------- | | God class | Extract Class | Do incrementally, move one method at a time | | Type-checking conditionals | Replace with Polymorphism | Requires class hierarchy | | Too many parameters | Introduce Parameter Object | Changes function signature | | Complex loop | Replace Loop with Pipeline | Ensure equivalent behavior |
Tie-breaker: If multiple refactorings apply, choose smallest scope first (Rename < Extract Variable < Extract Function < Extract Class).
After each refactoring:
refactor: [what changed]git checkout -- <changed-files>
After revert:
STOP. Ask user:
"I've attempted this refactoring twice and tests keep failing. This suggests either:
- The refactoring is too large (need smaller steps)
- The code has hidden dependencies
- Tests are brittle
How would you like to proceed?"
More refactoring needed?
├─ Yes → Return to Phase 3 (one more refactoring)
└─ No → Done
└─ Report: "Refactoring complete. Changes: [summary]"
Partial test coverage:
Refactoring reveals a bug:
User requests large refactoring:
| Don't | Do | | ------------------------------- | ------------------------------------- | | Batch multiple refactorings | One refactoring → test → commit | | "Fix" a failed refactoring | Revert, then try smaller step | | Refactor without tests | Add characterization tests first | | Change behavior during refactor | That's a feature/fix, not refactoring | | Skip the commit | Commit after every green test |
refactor: [description]development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.