| name | boy-scout-cleanup |
| description | Apply the Boy Scout Rule to existing code -- leave every file cleaner than you found it. Use this skill when the user is working in an existing codebase and asks to clean up code, improve existing files, apply the Boy Scout Rule, tidy up a module, or says things like "clean this up while you're in there," "this file needs some love," "improve this code," or "make this better." Performs incremental cleanup without changing behavior. |
Boy Scout Cleanup Skill
Use this skill to apply the Boy Scout Rule (Clean Code Pattern 11): leave every file cleaner than you found it. This is for incremental improvement, not full rewrites.
Cleanup Workflow
- Read the file(s) the user wants cleaned up
- Identify cleanup opportunities using the checklist below
- Categorize each by impact (HIGH / MEDIUM / LOW)
- Apply HIGH and MEDIUM fixes
- List LOW fixes as suggestions for the user to consider
- Verify no behavior changed (if tests exist, run them)
Boy Scout Cleanup Checklist
Work through each category in order:
1. Names (Pattern 1)
2. Dead Code
3. Function Length (Pattern 10)
4. Conditionals
5. Magic Values (Pattern 9)
6. Formatting (Pattern 8)
Rules
- Never change behavior. This is cleanup, not refactoring. The code must do exactly what it did before.
- Don't rewrite the file. Fix 3-5 things per pass. Incremental improvement compounds.
- Run tests after cleanup. If any test fails, revert that specific change.
- Don't add features. Don't add error handling that wasn't there, validation that wasn't there, or types that weren't there. That's enhancement, not cleanup.
- Respect existing patterns. If the codebase uses a specific style (even if you disagree), stay consistent with it.
Example
Before:
function proc(d) {
let r = [];
for (let i = 0; i < d.length; i++) {
if (d[i].active === true) {
if (d[i].age >= 18) {
r.push(d[i]);
}
}
}
return r;
}
After:
const MINIMUM_AGE = 18;
function filterEligibleUsers(users) {
return users.filter(user => user.active && user.age >= MINIMUM_AGE);
}
What changed:
- Renamed
proc to filterEligibleUsers (Pattern 1: Meaningful Names)
- Renamed
d to users, r to return value (Pattern 1)
- Replaced nested loop with
.filter() (Pattern 10: Short Functions)
- Simplified
=== true to truthy check (Pattern 4: Readability)
- Extracted
18 to MINIMUM_AGE constant (Pattern 9: No Hardcoded Values)
- Deleted commented-out code (Pattern 11: Boy Scout Rule)