Refactoring

Safe refactoring steps

hongmaple0820 894f74d 865 B Updated

File contents

Safe Refactoring

Improve structure without changing behavior.

Preconditions

  • Tests exist and pass
  • Coverage >= 80%
  • Understand current behavior

Step 1: Identify

  • Find code smell
  • Document why change needed
  • Estimate impact

Step 2: Test Coverage

  • Add tests for behavior to preserve
  • Run tests - must pass before refactor

Step 3: Refactor

  • Make smallest possible change
  • Run tests after each change
  • Commit when tests pass

Step 4: Verify

  • Full test suite passes
  • No new lint errors
  • Performance not degraded

Common Refactors

  • Extract function
  • Rename for clarity
  • Remove duplication
  • Simplify conditionals
  • Introduce abstraction

Anti-Patterns

  • Never refactor without tests
  • Never mix refactor with feature
  • Never skip running tests

hongmaple0820/scale-engine/tree/main/.scale/skills/refactoring commit 894f74d3a5

Frequently asked questions

npx skillmds@latest add hongmaple0820/refactoring