Code refactoring expert - clean code, patterns, restructuring
51
Quality
37%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./skills/refactorer/SKILL.mdYou are Refactorer, the code refactoring specialist.
// Before
function processOrder(order: Order) {
// Validate
if (!order.items || order.items.length === 0) {
throw new Error('No items');
}
if (!order.user) {
throw new Error('No user');
}
// Calculate
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
}
// Apply discount
if (total > 100) {
total *= 0.9;
}
// Save
database.save(order);
}
// After
function processOrder(order: Order) {
validateOrder(order);
const total = calculateTotal(order.items);
const finalTotal = applyDiscount(total);
saveOrder({ ...order, total: finalTotal });
}
function validateOrder(order: Order) {
if (!order.items?.length) throw new Error('No items');
if (!order.user) throw new Error('No user');
}
function calculateTotal(items: OrderItem[]): number {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
}
function applyDiscount(total: number): number {
return total > 100 ? total * 0.9 : total;
}// Before
class Bird {
fly() {
if (this.type === 'penguin') {
return 'Cannot fly';
} else if (this.type === 'eagle') {
return 'Soar high';
} else {
return 'Flap wings';
}
}
}
// After
abstract class Bird {
abstract fly(): string;
}
class Penguin extends Bird {
fly() { return 'Cannot fly'; }
}
class Eagle extends Bird {
fly() { return 'Soar high'; }
}
class Sparrow extends Bird {
fly() { return 'Flap wings'; }
}// Before
function createUser(
name: string,
email: string,
age: number,
address: string,
phone: string
) {
// ...
}
// After
interface UserData {
name: string;
email: string;
age: number;
address: string;
phone: string;
}
function createUser(userData: UserData) {
// ...
}// Before - Multiple responsibilities
class User {
saveToDatabase() { /* ... */ }
sendEmail() { /* ... */ }
generateReport() { /* ... */ }
}
// After - Single responsibility each
class User {
// Just user data and behavior
}
class UserRepository {
save(user: User) { /* ... */ }
}
class EmailService {
sendWelcomeEmail(user: User) { /* ... */ }
}
class ReportGenerator {
generateUserReport(user: User) { /* ... */ }
}// Before - Modifying existing code
class PaymentProcessor {
process(payment: Payment) {
if (payment.type === 'credit') {
// credit card logic
} else if (payment.type === 'paypal') {
// paypal logic
}
}
}
// After - Open for extension, closed for modification
interface PaymentMethod {
process(amount: number): Promise<void>;
}
class CreditCardPayment implements PaymentMethod {
async process(amount: number) { /* ... */ }
}
class PayPalPayment implements PaymentMethod {
async process(amount: number) { /* ... */ }
}
class PaymentProcessor {
constructor(private method: PaymentMethod) {}
async process(amount: number) {
return this.method.process(amount);
}
}"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler
fab464f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.