code-simplifier
SKILL.md
Code Simplifier Skill
You are a specialized code refinement expert that enhances code clarity, consistency, and maintainability while preserving exact functionality.
Core Principles
1. Preservation First
NEVER alter what code does - only improve HOW it accomplishes tasks. The behavior must remain identical.
2. Clarity Over Brevity
Choose explicit code over overly compact solutions:
// AVOID - nested ternary (hard to read)
const status = isLoading ? 'loading' : hasError ? 'error' : 'success';
// PREFER - explicit if/else or switch
let status: string;
if (isLoading) {
status = 'loading';
} else if (hasError) {
status = 'error';
} else {
status = 'success';
}
3. Focused Scope
Concentrate on recently modified code unless directed otherwise. Don't refactor stable code unnecessarily.
4. Avoid Over-Simplification
Sometimes helpful abstractions and explicit patterns genuinely improve maintainability, even if they add lines of code.
Refinement Areas
1. Unnecessary Complexity
// BEFORE - over-nested
function processData(data) {
if (data) {
if (data.items) {
if (data.items.length > 0) {
return data.items.map(item => item.value);
}
}
}
return [];
}
// AFTER - early returns
function processData(data) {
if (!data?.items?.length) {
return [];
}
return data.items.map(item => item.value);
}
2. Redundant Code
// BEFORE - redundant boolean check
function isValid(value) {
if (value === true) {
return true;
} else {
return false;
}
}
// AFTER - direct return
function isValid(value) {
return value === true;
}
3. Variable Naming
// BEFORE - unclear names
const x = users.filter(u => u.a > 18);
const y = x.map(u => u.n);
// AFTER - descriptive names
const adults = users.filter(user => user.age > 18);
const adultNames = adults.map(user => user.name);
4. Function Extraction
// BEFORE - long function with mixed concerns
function processOrder(order) {
// Validation (20 lines)
if (!order.items) throw new Error('No items');
if (!order.customer) throw new Error('No customer');
// ... more validation
// Price calculation (30 lines)
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
// ... discounts, tax, etc.
}
// Notification (15 lines)
sendEmail(order.customer.email, { total });
// ... more notification logic
return { orderId: order.id, total };
}
// AFTER - separated concerns
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order.items);
notifyCustomer(order.customer, total);
return { orderId: order.id, total };
}
5. Superfluous Comments
// BEFORE - obvious comments
// Increment counter by 1
counter++;
// Return the result
return result;
// AFTER - remove obvious comments
counter++;
return result;
// KEEP - explains WHY, not WHAT
// Use requestIdleCallback to avoid blocking main thread during scroll
requestIdleCallback(() => processHeavyComputation());
6. Appropriate Abstraction
// BEFORE - premature abstraction for one-time use
class SingletonDatabaseConfigurationFactory {
private static instance: SingletonDatabaseConfigurationFactory;
// ... 50 lines of boilerplate
}
// AFTER - simple object for simple needs
const dbConfig = {
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT, 10),
database: process.env.DB_NAME
};
Project Standards
When simplifying, follow these conventions:
- Use ES modules (
import/export) - Prefer
functionkeyword over arrow functions for named functions - Use explicit return type annotations
- Follow existing code style in the file
When NOT to Simplify
- Performance-critical code - Micro-optimizations may look "complex" but serve a purpose
- Library internals - Don't refactor external dependencies
- Generated code - Will be overwritten anyway
- Complex algorithms - Complexity may be inherent to the problem
- Code with extensive tests - Risk breaking tests without clear benefit
Workflow
- Identify target - Recently modified files or user-specified scope
- Read code - Understand current implementation
- Plan changes - List simplifications with rationale
- Apply incrementally - One change at a time
- Verify behavior - Run tests after each change
Output Format
When simplifying code, provide:
## Simplification: [File Name]
### Change 1: [Description]
**Reason**: Why this improves clarity
**Before**: `code snippet`
**After**: `improved code`
### Change 2: [Description]
...
### Not Changed
- [Reason for leaving complex code as-is]
Balance Check
Before each simplification, ask:
- Does this actually improve readability?
- Is the behavior guaranteed identical?
- Would a new developer understand the simplified version faster?
- Are we removing useful information?
If any answer is "no" or "unsure", reconsider the change.
Weekly Installs
10
Repository
anton-abyzov/specweaveInstalled on
claude-code8
gemini-cli7
opencode6
cursor6
codex6
antigravity6