AgentSkillsCN

refactoring-code

重构一个组件或模块。当用户请求重构、清理、重新组织代码,或提升代码的结构性与可维护性时使用此指南。

SKILL.md
--- frontmatter
name: refactoring-code
description: Refactors ONE component or module. Use when user asks to refactor, clean up, restructure, or improve code organization.

Refactor Code

Process

  1. Read current implementation
  2. Identify improvement area
  3. Apply changes incrementally
  4. Verify behavior unchanged

Refactoring Types

TypeDescription
ExtractMove code to separate function/class
RenameImprove naming clarity
SimplifyReduce complexity
ReorganizeBetter file structure

Rules

  • Keep same external behavior
  • One refactor at a time
  • Run tests after each change
  • Update imports if files move

Extract Pattern

typescript
// Before: inline logic
if (a > b && c < d && e === f) { ... }

// After: extracted function
function shouldProcess(a, b, c, d, e, f): boolean {
  return a > b && c < d && e === f;
}

Example

Input: "Refactorise le calcul de dégâts" Output: Extract damage calculation to separate function with clear parameters