Boy scout rule

From TheBushidoCollective/han · View interactive version

Boy scout rule is an AI agent skill from the GitHub repository TheBushidoCollective/han. Use when modifying existing files, refactoring, improving code quality, or touching legacy code by applying the Boy Scout Rule to leave code better than you found it.

How to use this skill

Skill file

Boy Scout Rule

"Leave the campground cleaner than you found it."

Always leave code better than you found it. Make incremental

improvements when you touch a file.

What to Improve

Code Quality:

What NOT to Do

Process

  1. Before changes: Read file, note obvious issues, run linter
  2. Make primary changes: Implement feature/fix, write tests
  3. Apply improvements: Fix linting, improve naming, add types,

extract constants, remove dead code

  1. Run verification: mix lint && mix test or

yarn test:lint && yarn ts:check && yarn test

  1. Document: Include boy scout changes in commit message

Example Commit Message

Add worker search filter

- Implement location-based filtering
- Add tests for search radius

Boy Scout improvements:
- Extract SEARCH_RADIUS constant
- Add type annotations to helper functions
- Remove unused import statements
- Improve variable naming in search logic

Example Improvements

Before:

function calculateTotal(items) {  // No types
  let t = 0;  // Poor naming
  for (let i = 0; i < items.length; i++) {  // Old-style
    t += items[i].price * 1.08;  // Magic number
  }
  return t;
}

After:

const TAX_RATE = 1.08;

function calculateTotal(items: Item[]): number {
  return items.reduce((total, item) => {
    return total + (item.price * TAX_RATE);
  }, 0);
}

Improvements: types, constant, naming, modern syntax, simplified.

Critical Rules

Checklist

Integration

During implementation: Make changes, apply boy scout, verify, commit together

During code review: Look for boy scout opportunities, recognize good boy scouting

During bug fixes: Fix bug, improve surrounding code, add tests, clean up

Remember

Incremental improvement, not perfection

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.