refactor-advisor
Skill907 starsChanged 4 months agoMITView on GitHub
重构顾问 - 识别代码坏味道并提供重构方案
2 other projects use a version of this.
Adopted by
Most recently taken up by
- aidankaokao/claude-skillstheir own version, first seen Oct 9, 2026
- liuxiao20051106-prog/claude-skillstheir own version, first seen Aug 10, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- liuxiao20051106-prog/claude-skills★ 1same name
- aidankaokao/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- docs/llms.txtllms.txt
- api-testerSkill
- changelog-genSkill
- db-migratorSkill
- dep-auditorSkill
- ds-mapperSkill
- env-managerSkill
- error-translatorSkill
- eslint-fixSkill
- github-actions-genSkill
- git-workflowSkill
- i18n-helperSkill
- log-analyzerSkill
- perf-profilerSkill
- security-auditSkill
- skill-curatorSkill
- test-generatorSkill
- zh-code-reviewerSkill
- zh-docgenSkill
- zh-readmeSkill
The file
Files
代码重构顾问
触发条件
当用户要求重构代码、优化代码结构、改善代码质量、消除技术债务时激活此技能。
工作流程
第 1 步:扫描代码库
- 使用
grep/rg扫描目标目录,识别潜在坏味道 - 统计文件行数、函数长度、参数数量等指标
- 查找重复代码块(相似度 > 80%)
第 2 步:分类坏味道
按严重程度分类发现的问题:
| 等级 | 含义 | 说明 |
| 🔴 严重 | 必须立即修复 | 影响可维护性和稳定性 |
| 🟡 中等 | 建议尽快修复 | 降低代码可读性 |
| 🟢 轻微 | 可择机优化 | 不影响功能但有改进空间 |
第 3 步:优先级排序
按以下维度综合排序:
- 影响范围 — 被引用/调用次数越多,优先级越高
- 变更频率 — git log 频繁改动的文件优先
- 修复成本 — 成本低且收益高的优先处理
第 4 步:输出重构方案
常见坏味道检测
| 坏味道 | 特征 | 重构手法 | 等级 |
| 长方法 | 函数超过 50 行 | 提取方法 (Extract Method) | 🔴 |
| 大类 | 类超过 300 行 | 提取类 (Extract Class) | 🔴 |
| 重复代码 | 相似代码块出现 3+ 次 | 提取公共方法 | 🔴 |
| 过长参数 | 函数参数超过 4 个 | 引入参数对象 | 🟡 |
| 嵌套过深 | if/for 嵌套 3+ 层 | 卫语句 (Guard Clause) | 🟡 |
| 魔法数字 | 硬编码的数字 | 提取为常量 | 🟢 |
| 过长链式调用 | a.b.c.d.e | 提取中间变量 | 🟢 |
| 全局可变状态 | 全局变量被多处修改 | 封装为模块/引入依赖注入 | 🔴 |
| 过度耦合 | 模块间相互依赖 | 依赖反转、引入接口 | 🟡 |
输出格式
完整报告模板
# 代码重构报告
## 概要
- 扫描文件数:XXX
- 发现问题数:XX(🔴 X / 🟡 X / 🟢 X)
- 预估工作量:X 天
## 问题列表
### 问题 1:[问题标题]
- **📍 位置**:`src/services/user.ts:45-120`
- **🔍 问题**:该函数长达 75 行,包含 3 层嵌套,职责不单一
- **🛠️ 重构方案**:
- 提取 `validateUserData()` 方法
- 提取 `saveToDatabase()` 方法
- 使用卫语句替代嵌套 if
- **⚠️ 风险评估**:
- 该函数被 12 处调用,需全面回归测试
- 建议先添加单元测试再重构
- **Before**:
```typescript
function processUser(data) { /* 75行... */ }- After:
function processUser(data) { const validated = validateUserData(data); return saveToDatabase(validated); }
重构路线图
| 阶段 | 内容 | 优先级 | 预估 |
| P1 | 修复 🔴 严重问题 | 高 | 2天 |
| P2 | 处理 🟡 中等问题 | 中 | 3天 |
| P3 | 优化 🟢 轻微问题 | 低 | 1天 |
## 注意事项
- 重构前确保有足够的测试覆盖
- 每次重构尽量小步提交,便于回滚
- 重构不应改变外部行为(行为保持)
- 大规模重构建议分阶段进行,每阶段独立可验证
- 关注重构过程中的性能回退风险Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

