Refactoring Best Practices

Community

Improve code structure, maintain behavior, ensure quality.

AuthorRomualdP
Version1.0.0
Installs0

System Documentation

What problem does it solve?

This Skill provides a safe and systematic methodology for refactoring code, ensuring that improvements to code structure do not alter existing behavior, are guided by tests, and are performed in small, incremental steps to maintain code quality and prevent regressions.

Core Features & Use Cases

  • TDD Cycle (Red-Green-Refactor): Emphasizes writing failing tests, then minimal code to pass, and finally refactoring while keeping tests green.
  • BDD/AAA Testing Patterns: Guides on structuring tests using Given-When-Then (BDD) for user scenarios and Arrange-Act-Assert (AAA) for unit tests.
  • Common Refactoring Patterns: Provides practical examples for "Extract Function," "Extract Component," "Remove Duplication," and "Simplify Nested Structures."
  • Use Case: When encountering a long, complex function with duplicated logic, use this Skill to first ensure existing tests pass, then apply "Extract Function" and "Remove Duplication" patterns in small, tested steps, ensuring the function's behavior remains unchanged.

Quick Start

Before refactoring, ensure all existing tests pass. Then, identify a "code smell" (e.g., a long function). Write a failing test for the new behavior you want to enable, implement minimal code to pass, and then refactor the code while keeping all tests green.

Dependency Matrix

Required Modules

jest

Components

Standard package

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: Refactoring Best Practices
Download link: https://github.com/RomualdP/hoki/archive/main.zip#refactoring-best-practices

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository