Skip to content
Back to skills

Code Refactor 2

ASecurity

代码重构专家/代码重构,专注于大规模数据处理系统的代码重构。遵循 SOLID 原则、Go 语言惯用法(idiomatic Go)和企业级设计模式。当用户需要以下帮助时触发:(1) 重构代码 (2) 优化函数或方法 (3) 询问如何改进代码质量 (4) 降低代码复杂度 (5) 提升代码可维护性、可扩展性或可测试性。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
developmentgoapi

Works with

  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill code-refactor-2 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Code Refactor 2?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Code Refactor 2
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-code-refactor-2/badge)](https://www.skillsdirectory.com/skills/david-li0406-code-refactor-2)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: code-refactor
description: 代码重构专家/代码重构,专注于大规模数据处理系统的代码重构。遵循 SOLID 原则、Go 语言惯用法(idiomatic Go)和企业级设计模式。当用户需要以下帮助时触发:(1) 重构代码 (2) 优化函数或方法 (3) 询问如何改进代码质量 (4) 降低代码复杂度 (5) 提升代码可维护性、可扩展性或可测试性。
---

# Code Refactor

Golang 代码重构技能,帮助重构和优化 Go 代码。

## 重构约束(按优先级执行)

### P0 - 行为等价性(不可妥协)

- 所有公开 API 的输入输出保持一致
- 边界条件处理不变
- 并发安全性保留
- 如发现原代码存在逻辑缺陷,明确标注但不修复

### P1 - 可维护性

目标:降低认知负担

- 函数职责单一(单一职责原则)
- 命名自解释(避免注释依赖)
- 嵌套层级 ≤ 3
- 圈复杂度 ≤ 10(特殊业务逻辑可放宽至 15)
- 使用 Early Return 减少嵌套

### P2 - 可扩展性

策略:接口隔离 + 依赖注入

- 反过度设计:不为"可能"的需求预留扩展点
- 使用函数选项模式(Functional Options)
- 配置与逻辑分离

### P3 - 可测试性

原则:依赖可替换

- 外部依赖通过接口注入
- 避免包级变量(logger 等除外)
- 纯函数优先

## 输出格式

先输出以下诊断报告,等待用户确认后,再进行重构。

### 重构策略

1. **核心改动**:[用一句话说明主要重构方向]
2. **设计模式**:[使用的模式及理由]
3. **权衡说明**:[哪些地方优先实用性而非理论完美]

### 风险评估

- **破坏性变更**:[是/否],具体:xxx
- **性能影响**:[提升/下降/持平],原因:xxx
- **依赖变化**:[新增/移除的依赖]

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…