From code-refactorer
Refactors code in specified file or directory: improves structure, removes duplication, optimizes performance, enhances maintainability, adds tests and documentation.
npx claudepluginhub devsforge/marketplace --plugin code-refactorer# Code Refactoring Command Refactor existing code to improve quality, maintainability, and performance while preserving functionality. ## Usage **Examples:** ## What This Command Does This command analyzes code and performs systematic refactoring to: 1. **Improve Code Structure** - Extract complex functions into smaller, focused units - Apply SOLID principles for better maintainability - Remove code duplication (DRY principle) - Improve naming for clarity and self-documentation 2. **Enhance Performance** - Optimize algorithms and data structures - Remove performa...
/refractorRefactors provided code following best practices and design patterns. Maintains functionality; improves readability, extracts reusable components, optimizes performance, applies modern conventions, adds type safety. Explains each change.
/refractorRefactors provided code following best practices and design patterns. Maintains functionality; improves readability, extracts reusable components, optimizes performance, applies modern conventions, adds type safety. Explains each change.
/refractorRefactors provided code following best practices and design patterns. Maintains functionality; improves readability, extracts reusable components, optimizes performance, applies modern conventions, adds type safety. Explains each change.
Refactor existing code to improve quality, maintainability, and performance while preserving functionality.
/refractor <file_or_directory>
Examples:
/refractor src/components/UserManager.js
/refractor src/services/
/refractor app/models/payment_processor.py
This command analyzes code and performs systematic refactoring to:
Improve Code Structure
Enhance Performance
Increase Maintainability
First, analyze the target code:
Rank refactoring opportunities by:
Apply refactoring techniques incrementally:
Extract Method: Break down complex functions
// Before
function processOrder(order) {
// 50 lines of mixed responsibilities
}
// After
function processOrder(order) {
validateOrder(order);
calculateTotal(order);
applyDiscounts(order);
processPayment(order);
sendConfirmation(order);
}
Remove Duplication: Apply DRY principle
# Before
def calculate_price_with_tax_us(price):
return price * 1.08
def calculate_price_with_tax_uk(price):
return price * 1.20
# After
def calculate_price_with_tax(price, tax_rate):
return price * (1 + tax_rate)
Improve Naming: Use descriptive names
// Before
function calc(a: number, b: number): number {
return a * b * 0.15;
}
// After
function calculateCommissionAmount(
salesPrice: number,
quantity: number
): number {
const COMMISSION_RATE = 0.15;
return salesPrice * quantity * COMMISSION_RATE;
}
Validate refactoring:
Update relevant documentation:
# Before
def get_speed(vehicle_type):
if vehicle_type == "car":
return 100
elif vehicle_type == "bike":
return 50
elif vehicle_type == "plane":
return 900
# After
class Vehicle:
def get_speed(self):
raise NotImplementedError
class Car(Vehicle):
def get_speed(self):
return 100
class Bike(Vehicle):
def get_speed(self):
return 50
// Before
public void createUser(String name, String email, String phone, String address, String city) {
// ...
}
// After
public void createUser(UserDetails details) {
// ...
}
// Before
if (user.age > 18 && user.accountBalance > 1000) {
approveCredit();
}
// After
const MINIMUM_AGE = 18;
const MINIMUM_BALANCE = 1000;
if (user.age > MINIMUM_AGE && user.accountBalance > MINIMUM_BALANCE) {
approveCredit();
}
Track these metrics before and after refactoring:
This command follows industry best practices: