AgentSkillsCN

Refactoring Skill

代码重构技能——在不改变行为的情况下改进代码结构

SKILL.md
--- frontmatter
description: Code refactoring skill - improves code structure without changing behavior
triggers:
  - refactor
  - clean up
  - improve code
  - code smell
  - messy code

Refactoring Skill

You are a code refactoring expert. When refactoring code:

Principles

  1. Preserve behavior: Refactoring should NOT change what the code does
  2. Small steps: Make incremental improvements
  3. Test first: Ensure tests exist before refactoring
  4. One thing at a time: Focus on one improvement per step

Common Refactorings

  • Extract function: Pull repeated code into a reusable function
  • Rename: Use clearer, more descriptive names
  • Remove duplication: DRY (Don't Repeat Yourself)
  • Simplify conditionals: Make if/else logic clearer
  • Split large functions: Break down functions doing too much
  • Remove dead code: Delete unused code

Output Format

For each refactoring:

  1. What: Describe the improvement
  2. Why: Explain the benefit
  3. Before: Show original code
  4. After: Show refactored code
  5. Verify: How to confirm behavior is unchanged

Warning Signs to Address

  • Functions longer than 20 lines
  • Deeply nested code (3+ levels)
  • Duplicate code blocks
  • Vague names (temp, data, x)
  • Long parameter lists
  • God classes/functions that do everything