agentleFS
sbrudzsbrudz/agent-skills/skills/boy-scout-rule/SKILL.md

boy-scout-rule

Skill2 starsChanged 9 months agoMITView on GitHub

Use after making tests pass to apply incremental refactoring improvements to touched code and its immediate neighbors, during code review, or before committing changes

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    The guardrail: If a refactoring would show up as an unrelated change in a code review diff, it's out of scope.

    line 18
  2. Distinctive:

    Run through after tests go green.

    line 22
  3. Very specific:

    If code mixes business logic with I/O → apply functional-core-imperative-shell checklist

    line 50
  4. Very specific:

    If code is React (.tsx/.jsx) → apply react-best-practices Section 1 (component responsibility)

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Boy Scout Rule — Leave the Code Cleaner Than You Found It

Concrete refactoring checklist for after tests pass and during code review. Replaces vague "clean up" guidance with specific patterns to look for.

Scope

Refactor: touched code + immediate neighbors.

  • Touched code: Anything you wrote or modified in this task.
  • Immediate neighbors: Functions your code calls, functions that call your code, types your code uses. If your changes made adjacent code harder to read or revealed existing mess, clean it up.
  • Out of scope: Code you only read for context. Refactoring that would require new tests beyond the task's scope — note it as a follow-up task instead.

The guardrail: If a refactoring would show up as an unrelated change in a code review diff, it's out of scope.

Refactor Checklist

Run through after tests go green. Check your code and its immediate neighbors.

Structural clarity

  • Extract function — Any code block doing a distinct thing that you have to read to understand? Name it.
  • Reduce nesting — More than 2 levels of indentation? Use early returns, guard clauses, or extract the inner logic.
  • Simplify conditionals — Complex boolean expression? Extract to a named variable or function (isEligibleForDiscount instead of total > 100 && !isTrial && coupon.active).
  • Rename for clarity — Do names describe what, not how? Would a new team member understand without reading the implementation?

Structural design

  • Consolidate duplication — Did you write something similar to existing code? Three similar implementations = extract the common pattern. Two might be coincidence.
  • Right-size functions — Does any function do more than one thing? Split by responsibility. If you can't describe what it does without "and," it's too big.
  • Flatten data flow — Is data passed through intermediaries that don't use it? Restructure to reduce pass-through.

Code Review Refactor Checklist

Apply during code review. The reviewer has the full diff and can spot cross-cutting patterns.

Cross-cutting patterns

  • Emerging abstractions — Did multiple tasks create similar code? Three similar implementations is the signal to consolidate.
  • Inconsistent patterns — Does the new code handle something differently from existing code nearby? Pick one pattern and make them consistent.
  • Growing modules — Did this task push a file past the point where it's easy to navigate? Flag for splitting.
  • Leaky abstractions — Does the caller need to know implementation details to use this code correctly? Tighten the interface.

Related skill checks

  • If code mixes business logic with I/O → apply functional-core-imperative-shell checklist
  • If code is React (.tsx/.jsx) → apply react-best-practices Section 1 (component responsibility)

What NOT to flag as refactoring

  • Formatting/whitespace changes — that's the linter's job
  • Renaming across the whole codebase when only one file was touched
  • Refactoring that would require its own unrelated tests — note as a follow-up task

Related Skills

  • Prerequisite: visual-feedback-loop (for UI tasks — verify appearance before refactoring)
  • Pairs with: functional-core-imperative-shell (if code mixes business logic with I/O), react-best-practices (if code is React), domain-driven-design (rename to match ubiquitous language)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.