Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality.
by @ksky521
Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestio...
clawhub install code-smell-analyzerπ About This Skill
name: 'code-smell-analyzer' description: 'Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality.' version: '1.0.0'
Code Smell Analyzer
Analyzes code files for potential improvements including code smells, design patterns, and best practices. Provides suggestions for enhancing readability, maintainability, and performance while preserving functionality.
When to Use
Invoke this skill when:
Analysis Framework
1. Code Smells
Identify any code smells such as:
2. Design Patterns
Suggest appropriate design patterns that could improve the code structure:
3. Best Practices
Check adherence to language-specific best practices:
4. Readability
Evaluate code clarity:
5. Maintainability
Assess how easy the code would be to modify and extend:
6. Performance
Identify potential performance optimizations:
Output Format
For each suggestion, provide:
Issue Description
Clear explanation of the issue or improvement opportunity.
Current Code
// Show the problematic code
Suggested Improvement
// Show the improved code
Rationale
Explain why the change would be beneficial.
Priority
Example Analysis
Issue: Long Method with Multiple Responsibilities
Priority: High
Current Code:
function processOrder(order) {
// Validate order
if (!order.items || order.items.length === 0) {
throw new Error('Order has no items');
}
if (!order.customer) {
throw new Error('Customer is required');
} // Calculate totals
let subtotal = 0;
for (const item of order.items) {
subtotal += item.price * item.quantity;
}
const tax = subtotal * 0.1;
const total = subtotal + tax;
// Apply discount
if (order.discountCode) {
total = total * 0.9;
}
// Save to database
db.orders.insert({
...order,
subtotal,
tax,
total,
createdAt: new Date(),
});
// Send confirmation email
emailService.send(order.customer.email, 'Order Confirmed', total);
return {orderId: order.id, total};
}
Suggested Improvement:
function processOrder(order) {
validateOrder(order);
const pricing = calculatePricing(order);
saveOrder(order, pricing);
sendConfirmation(order, pricing.total);
return {orderId: order.id, total: pricing.total};
}function validateOrder(order) {
if (!order.items?.length) throw new Error('Order has no items');
if (!order.customer) throw new Error('Customer is required');
}
function calculatePricing(order) {
const subtotal = order.items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const tax = subtotal * 0.1;
let total = subtotal + tax;
if (order.discountCode) {
total *= 0.9;
}
return {subtotal, tax, total};
}
function saveOrder(order, pricing) {
db.orders.insert({
...order,
...pricing,
createdAt: new Date(),
});
}
function sendConfirmation(order, total) {
emailService.send(order.customer.email, 'Order Confirmed', total);
}
Rationale:
Language-Specific Considerations
JavaScript/TypeScript
const/let instead of var?.) and nullish coalescing (??)any type in TypeScriptPython
with statements)Java
WeChat Mini Program
wx:key for list rendering