From claude-dotfiles
Safe refactoring patterns and techniques. Use when the user wants to improve code structure, reduce duplication, or make code more maintainable without changing behavior. Emphasizes incremental changes with test coverage.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-dotfiles:refactoring-guideThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Improve code structure safely without changing behavior.
Improve code structure safely without changing behavior.
1. Ensure tests exist and pass
↓
2. Identify the code smell
↓
3. Choose appropriate refactoring technique
↓
4. Make small change
↓
5. Run tests
↓
6. Commit if green, revert if red
↓
7. Repeat until done
Symptom: Function > 20-30 lines, multiple responsibilities
Refactoring: Extract Method
// Before
function processOrder(order: Order) {
// Validate order (10 lines)
// Calculate totals (15 lines)
// Apply discounts (12 lines)
// Update inventory (8 lines)
// Send confirmation (10 lines)
}
// After
function processOrder(order: Order) {
validateOrder(order);
const totals = calculateTotals(order);
const finalTotal = applyDiscounts(totals, order.discounts);
updateInventory(order.items);
sendConfirmation(order, finalTotal);
}
Symptom: Similar code in multiple places
Refactoring: Extract to shared function
// Before
function getUserName(user: User) {
return `${user.firstName} ${user.lastName}`.trim();
}
function getCustomerName(customer: Customer) {
return `${customer.firstName} ${customer.lastName}`.trim();
}
// After
function formatFullName(entity: { firstName: string; lastName: string }) {
return `${entity.firstName} ${entity.lastName}`.trim();
}
Symptom: Function with > 3-4 parameters
Refactoring: Introduce Parameter Object
// Before
function createUser(
name: string,
email: string,
age: number,
address: string,
phone: string,
role: string
) { ... }
// After
interface CreateUserInput {
name: string;
email: string;
age: number;
address: string;
phone: string;
role: string;
}
function createUser(input: CreateUserInput) { ... }
Symptom: Deep if/else nesting
Refactoring: Guard Clauses / Early Returns
// Before
function getDiscount(user: User) {
if (user) {
if (user.isActive) {
if (user.isPremium) {
return 0.2;
} else {
return 0.1;
}
}
}
return 0;
}
// After
function getDiscount(user: User) {
if (!user) return 0;
if (!user.isActive) return 0;
if (user.isPremium) return 0.2;
return 0.1;
}
Symptom: Unexplained literal values in code
Refactoring: Extract Constant
// Before
if (user.age >= 21) { ... }
if (status === 'PNDG') { ... }
// After
const MINIMUM_AGE = 21;
const ORDER_STATUS = {
PENDING: 'PNDG',
COMPLETE: 'CMPL',
} as const;
if (user.age >= MINIMUM_AGE) { ... }
if (status === ORDER_STATUS.PENDING) { ... }
Symptom: Method uses data from another class more than its own
Refactoring: Move Method
// Before
class Order {
getCustomerDiscount() {
if (this.customer.loyaltyYears > 5) {
return this.customer.baseDiscount * 1.5;
}
return this.customer.baseDiscount;
}
}
// After
class Customer {
getDiscount() {
if (this.loyaltyYears > 5) {
return this.baseDiscount * 1.5;
}
return this.baseDiscount;
}
}
| Smell | Technique |
|---|---|
| Long function | Extract Method |
| Duplicate code | Extract Function/Class |
| Long parameter list | Parameter Object |
| Nested conditionals | Guard Clauses |
| Magic values | Extract Constant |
| Feature envy | Move Method |
| Large class | Extract Class |
| Primitive obsession | Value Object |
| Switch statements | Replace with Polymorphism |
Before refactoring:
During refactoring:
After refactoring:
npx claudepluginhub peopleforrester/claude-dotfilesGuides collaborative design exploration before implementation: explores context, asks clarifying questions, proposes approaches, and writes a design doc for user approval.
Creates structured, bite-sized implementation plans from specs or requirements before writing code. Useful for breaking down multi-step tasks into testable steps with file structure and task boundaries.
Resolves in-progress git merge or rebase conflicts by analyzing history, understanding intent, and preserving both changes where possible. Runs automated checks after resolution.