AgentSkillsCN

refactor

对代码进行重构,提升结构清晰度、可读性和可维护性。当代码需要按照 SOLID、DRY、KISS 原则进行清理,或需添加类型注解、降低复杂度、优化命名,或采用当前语言的最佳实践进行现代化改造时,可使用此技能。同时,代码的行为将被完整保留。

SKILL.md
--- frontmatter
name: refactor
description: Refactor code for improved structure, readability, and maintainability. Use when code needs cleanup following SOLID/DRY/KISS principles, adding type hints, reducing complexity, improving naming, or modernizing to current language idioms. Preserves behavior.

Refactor

Improve code structure without changing behavior.

Constraints

RuleLimit
Function length< 40 lines
Cyclomatic complexity< 10
Nesting depth< 4 levels

Actions

  1. Break large functions into small, pure functions
  2. Add type annotations (no Any, no interface{})
  3. Rename variables descriptively (no x, data, temp)
  4. Extract magic numbers to constants
  5. Use modern language idioms (Python 3.12+, Go 1.22+, ESNext)

Output

Full refactored code only. No explanations.

For significant changes, add a comment header:

python
# Refactored:
# - Extracted validation logic
# - Added type hints
# - Renamed variables