refactor

Refactor TypeScript code with incremental changes while keeping tests green.

1|Updated Jan 13, 2023
One-click install
npx skills add https://github.com/theodrosyimer/.dotfiles --skill refactor-theodrosyimer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/theodrosyimer/.dotfiles/tree/main/claude/skills/dev__refactor
Command: npx skills add https://github.com/theodrosyimer/.dotfiles --skill refactor-theodrosyimer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guides the TDD refactor phase to improve code quality without altering behavior, ensuring that all existing tests stay green throughout the process.

Core Features & Use Cases

  • Test Safety: Guarantees test files remain untouched and all tests stay green after each change.
  • Incremental Refactoring: Provides step‑by‑step instructions for one change at a time with automatic test runs and LCOM analysis.
  • Architecture Compliance: Executes architecture tests and enforces LCOM thresholds for domain, infrastructure, and shared layers.
  • Use Case: When refactoring a TypeScript codebase under TDD, use this skill to systematically improve structure while continuously validating behavior and design quality.

Quick Start

Ask the refactor skill to improve the specified code area while keeping all tests green.

Frequently Asked Questions about refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor TypeScript code while keeping my TDD tests green?

You can refactor TypeScript code by applying incremental changes one step at a time, running vitest baseline commands after each modification to ensure tests stay green. This guarantees behavior preservation while improving internal structure.

What is LCOM metric enforcement in code refactoring?

LCOM metric enforcement in refactoring validates Lack of Cohesion in Modules to ensure classes maintain focused responsibilities. It automatically checks LCOM thresholds across domain, infrastructure, and shared layers during structural improvements.

How do I run architecture tests during a TDD refactor phase?

You run architecture tests during the TDD refactor phase by executing automated checks that validate layer dependencies for domain, infrastructure, and shared components. This ensures structural changes comply with defined architectural boundaries.

Can I modify test files when refactoring code under TDD?

No, you cannot modify test files during a TDD refactor phase because a test file lock is enforced. This guarantees existing tests remain untouched, ensuring behavior is verified by the original test suite throughout the structural improvement process.

Does this refactoring approach work without existing vitest tests?

No, this refactoring approach requires existing vitest tests to validate behavior. It runs baseline vitest commands to ensure tests stay green, meaning your TypeScript codebase must already have test coverage before structural changes begin.

What's the best way to improve code structure without altering behavior?

The best way to improve code structure without altering behavior is through incremental refactoring with continuous test validation. Execute changes one at a time, run tests automatically, and enforce LCOM thresholds to systematically improve design quality.