skills/refactoring-to-patterns/SKILL.md
Fowler's refactoring methodology — loaded by the implementer agent when working with existing code to recognize code smells and apply proven transformations
npx skillsauth add bostonaholic/team refactoring-to-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Refactoring is the process of changing the internal structure of code without changing its observable behavior. Every refactoring step must leave all tests passing. Never refactor while also adding features — separate the two activities.
Refactor when you need to:
Do NOT refactor when:
Smell: A function that is too long to understand in one reading (~30+ lines is a guideline, not a rule — some 10-line functions are too long).
Refactorings:
Smell: The same structure appears in two or more places. The danger: a bug in the pattern must be fixed in every copy.
Refactorings:
Smell: A class has too many responsibilities, indicated by many instance variables, many methods, or methods that use only a subset of variables.
Refactorings:
Smell: A function with four or more parameters is hard to call correctly and hard to remember.
Refactorings:
Smell: A single class changes for multiple different reasons — every time X happens you change one set of methods, every time Y happens you change a different set. This is SRP violation made visible.
Refactorings:
Smell: One logical change requires small edits to many different classes. The opposite of Divergent Change: behavior that should be together is spread apart.
Refactorings:
Smell: A method that seems more interested in another class's data than its own — it uses getters to pull out data and compute something.
Refactorings:
Smell: Using primitives (strings, integers, booleans) to represent domain concepts — phone numbers as strings, money as floats, status as magic string constants.
Refactorings:
Smell: Complex chains of if/else or switch that must be updated every
time a new variant is added. Frequently accompanies Primitive Obsession.
Refactorings:
Smell: A single function alternates between high-level orchestration ("save the order, charge the card, send the receipt") and low-level primitives ("for each line, format the price as fixed-width 8 chars"). Readers must repeatedly swap mental contexts. Often a sign of an unextracted helper.
Refactorings:
Smell: A class that delegates most of its methods to another class. If half or more of a class's public methods just forward to another class, the middle man adds no value.
Refactorings:
Smell: A class instantiates its dependencies inside methods
(new HttpClient() inside fetchUser()), takes per-call work parameters
in the constructor (new ReportGenerator(2024, 1, 1, 2024, 12, 31)), or
does I/O / static lookups in the constructor. No seam exists for tests to
substitute collaborators.
Refactorings:
new them inside.This creates a seam: production wires real collaborators through DI; tests substitute fakes or stubs at construction.
Every refactoring step must follow this sequence:
When working with existing code during implementation:
data-ai
Todo-first progress convention for multi-step procedures — loaded by every multi-step agent to track its own steps without drift
testing
Adversarially review a technical design document with fresh context before the human gate. Dispatches the built-in `general-purpose` subagent (clean context, no shared history with the design-author) against `docs/plans/<id>/design.md` and presents its verdict — APPROVE, REQUEST CHANGES, or COMMENT. Optional, not part of the QRSPI pipeline. Trigger on "review the design doc", "audit design.md", "is this design ready", or `/eng-design-doc-review`.
development
Generator-evaluator separation and review methodology — loaded by review agents to enforce fresh-context review discipline, Conventional Comments format, and gate verdicts
data-ai
Prepare one or more isolated git worktrees — one per repository the topic touches. Router action — no agent. Trigger on "set up the worktree", "isolate this work", or "/team-worktree".