Refine code for clarity, consistency, and maintainability without changing behavior. Use this skill whenever the user says "simplify", "clean up this code", "reduce complexity", "code smell", "make this more readable", "refactor for clarity", "tidy up", or "this code is messy". Also activate after completing a coding task, fixing a bug, or finishing an implementation when the resulting code could be clearer. Make sure to use this skill whenever the user mentions simplifying, cleaning up, or improving code readability, even if they don't explicitly ask for it.
Refine recently modified code for clarity, consistency, and maintainability. Preserve exact functionality while improving how code is written.
Do not change what the code does. All original features, outputs, and behaviors must remain intact. Only change how the code expresses its logic.
// increment counter on count++ add noise without value.if/else or switch because nested ternaries are notoriously hard to read and debug; even experienced developers have to slow down to parse them.if/else is easier to understand than a compact one-liner with multiple operators.Follow established coding conventions found in project config and instructions:
function keyword over arrow functions)Avoid over-simplifying:
Only refine recently modified code unless explicitly asked to review broader scope.
Before:
function getDiscount(user: User): number {
if (user.isActive) {
if (user.tier === 'premium') {
if (user.yearsActive > 2) {
return 0.20;
} else {
return 0.10;
}
} else {
return 0.05;
}
} else {
return 0;
}
}
After:
function getDiscount(user: User): number {
if (!user.isActive) return 0;
if (user.tier !== 'premium') return 0.05;
return user.yearsActive > 2 ? 0.20 : 0.10;
}
Before:
const label = status === 'active' ? 'Active' : status === 'pending' ? 'Pending Review' : status === 'archived' ? 'Archived' : 'Unknown';
After:
function getStatusLabel(status: string): string {
switch (status) {
case 'active': return 'Active';
case 'pending': return 'Pending Review';
case 'archived': return 'Archived';
default: return 'Unknown';
}
}
const label = getStatusLabel(status);
After simplification, report:
## Simplification Report
### Changes Applied
- **[file:line]**: [What changed] - [Why it improves the code]
### Standards Compliance
- [x] Naming conventions followed
- [x] Import ordering correct
- [x] No nested ternaries
- [x] Error handling patterns applied
### Verification
- [x] All original behavior preserved
- [x] No logic changes introduced