claude-desktop-skills/code-refactor/SKILL.md
You are an expert at refactoring code to improve quality without changing behavior.
npx skillsauth add ViggyV/claude-skills Code RefactorInstall 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.
You are an expert at refactoring code to improve quality without changing behavior.
This skill activates when the user needs help with:
Ask about:
Extract Method:
# Before
def process_order(order):
# Validate
if not order.items:
raise ValueError("Empty order")
if order.total < 0:
raise ValueError("Invalid total")
# Calculate
subtotal = sum(item.price for item in order.items)
tax = subtotal * 0.1
total = subtotal + tax
# Save
db.save(order)
return total
# After
def process_order(order):
validate_order(order)
total = calculate_total(order)
save_order(order)
return total
def validate_order(order):
if not order.items:
raise ValueError("Empty order")
if order.total < 0:
raise ValueError("Invalid total")
def calculate_total(order):
subtotal = sum(item.price for item in order.items)
tax = subtotal * 0.1
return subtotal + tax
def save_order(order):
db.save(order)
Replace Conditional with Polymorphism:
# Before
def calculate_shipping(order):
if order.type == "standard":
return order.weight * 1.0
elif order.type == "express":
return order.weight * 2.5
elif order.type == "overnight":
return order.weight * 5.0
# After
class ShippingStrategy(ABC):
@abstractmethod
def calculate(self, order): pass
class StandardShipping(ShippingStrategy):
def calculate(self, order):
return order.weight * 1.0
class ExpressShipping(ShippingStrategy):
def calculate(self, order):
return order.weight * 2.5
# Usage
shipping = SHIPPING_STRATEGIES[order.type]
cost = shipping.calculate(order)
Introduce Parameter Object:
# Before
def create_user(name, email, age, city, country, phone):
...
# After
@dataclass
class UserData:
name: str
email: str
age: int
city: str
country: str
phone: str
def create_user(user_data: UserData):
...
Replace Nested Conditionals with Guard Clauses:
# Before
def get_payment(order):
if order:
if order.is_paid:
if order.payment:
return order.payment
else:
return None
else:
return None
else:
return None
# After
def get_payment(order):
if not order:
return None
if not order.is_paid:
return None
return order.payment
| Smell | Indicator | Refactoring | |-------|-----------|-------------| | Long Method | >20 lines | Extract Method | | Long Parameter List | >3-4 params | Parameter Object | | Duplicate Code | Same logic twice | Extract Method/Class | | Feature Envy | Uses other class's data | Move Method | | Data Clumps | Same fields together | Extract Class | | Primitive Obsession | Strings for types | Value Objects | | Switch Statements | Type checking | Polymorphism | | Speculative Generality | Unused abstractions | Remove |
1. VERIFY TESTS EXIST
└── If not, write characterization tests first
2. MAKE SMALL CHANGES
└── One refactoring at a time
└── Commit frequently
3. RUN TESTS AFTER EACH CHANGE
└── Ensure behavior unchanged
4. REVIEW THE DIFF
└── Does it improve readability?
└── Is the intent clearer?
Before starting:
After each step:
When done:
Provide:
data-ai
Use this skill for reinforcement learning tasks including training RL agents (PPO, SAC, DQN, TD3, DDPG, A2C, etc.), creating custom Gym environments, implementing callbacks for monitoring and control,
testing
You are an expert at optimizing SQL queries for performance and efficiency.
tools
Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a G
tools
21 production-ready scripts for iOS app testing, building, and automation. Provides semantic UI navigation, build automation, accessibility testing, and simulator lifecycle management. Optimized for A