refactor-assistant

Refactor Assistant Skill

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "refactor-assistant" with this command: npx skills add aidotnet/moyucode/aidotnet-moyucode-refactor-assistant

Refactor Assistant Skill

Description

Improve code quality through systematic refactoring with design pattern recommendations.

Trigger

  • /refactor command

  • User requests code improvement

  • User asks about design patterns

Prompt

You are a refactoring expert that improves code quality while preserving behavior.

Extract Method

// ❌ Before: Long method with multiple responsibilities function processOrder(order: Order) { // Validate order if (!order.items.length) throw new Error('Empty order'); if (!order.customer) throw new Error('No customer');

// Calculate total let total = 0; for (const item of order.items) { total += item.price * item.quantity; if (item.discount) { total -= item.discount; } }

// Apply tax const tax = total * 0.1; total += tax;

// Save and notify db.save(order); emailService.send(order.customer.email, Order total: ${total}); }

// ✅ After: Small, focused methods function processOrder(order: Order) { validateOrder(order); const total = calculateTotal(order); saveAndNotify(order, total); }

function validateOrder(order: Order): void { if (!order.items.length) throw new Error('Empty order'); if (!order.customer) throw new Error('No customer'); }

function calculateTotal(order: Order): number { const subtotal = order.items.reduce((sum, item) => { const itemTotal = item.price * item.quantity - (item.discount ?? 0); return sum + itemTotal; }, 0); return subtotal * 1.1; // Include 10% tax }

Strategy Pattern

// ❌ Before: Switch statement for different behaviors function calculateShipping(order: Order): number { switch (order.shippingMethod) { case 'standard': return order.weight * 0.5; case 'express': return order.weight * 1.5 + 10; case 'overnight': return order.weight * 3 + 25; default: throw new Error('Unknown method'); } }

// ✅ After: Strategy pattern interface ShippingStrategy { calculate(order: Order): number; }

class StandardShipping implements ShippingStrategy { calculate(order: Order): number { return order.weight * 0.5; } }

class ExpressShipping implements ShippingStrategy { calculate(order: Order): number { return order.weight * 1.5 + 10; } }

class ShippingCalculator { constructor(private strategy: ShippingStrategy) {}

calculate(order: Order): number { return this.strategy.calculate(order); } }

Factory Pattern

// ✅ Factory for creating different notification types interface Notification { send(message: string): Promise<void>; }

class NotificationFactory { static create(type: 'email' | 'sms' | 'push'): Notification { switch (type) { case 'email': return new EmailNotification(); case 'sms': return new SmsNotification(); case 'push': return new PushNotification(); } } }

// Usage const notification = NotificationFactory.create('email'); await notification.send('Hello!');

Tags

refactoring , design-patterns , code-quality , clean-code , architecture

Compatibility

  • Codex: ✅

  • Claude Code: ✅

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

bilibili-analyzer

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

puppeteer

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

cron-scheduler

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

exceljs

No summary provided by upstream source.

Repository SourceNeeds Review