Refactor and Cleanup Guide
Use this skill when tasked with improving code quality, reducing complexity, or removing unused code.
Strategy
- •
Identify Targets: Look for:
- •Unused imports (VS Code usually greys these out).
- •Commented-out code blocks (delete them).
- •Long functions (> 50 lines).
- •Duplicated logic (DRY principle).
- •
Safety First:
- •Ensure tests pass before and after refactoring.
- •Do not change public API behavior unless explicitly requested.
- •
Specific Actions:
- •Consolidate Types: Move interfaces to
types/ordto/if used in multiple places. - •Extract Components: If a React component is too large, extract smaller components into separate files.
- •Simplify Conditionals: Use early returns to reduce nesting levels.
- •Improve Naming: Rename variables/functions to be more descriptive.
- •Consolidate Types: Move interfaces to
- •
Tools:
- •Use
eslint --fixto automatically fix formatting and linting issues. - •Use
prettierto format code.
- •Use
Checklist
- • No unused variables/imports.
- • No
console.logstatements (use logger). - • Types are explicit (avoid
any). - • Code builds and runs without errors.