Skip to content
FunCoding

Search

Search docs, Skills and MCP

refactor-advisor

重构顾问 - 识别代码坏味道并提供重构方案

代码质量与审查879skills/refactor-advisor/SKILL.md

Install

Send this to Claude Code, Codex or Cursor. The agent checks the Skill for safety first and installs it only after you confirm.

读取 https://funcoding.ai/skills/laolaoshiren/claude-code-skills-zh/refactor-advisor/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

代码重构顾问

触发条件

当用户要求重构代码、优化代码结构、改善代码质量、消除技术债务时激活此技能。

工作流程

第 1 步:扫描代码库

  • 使用 grep/rg 扫描目标目录,识别潜在坏味道
  • 统计文件行数、函数长度、参数数量等指标
  • 查找重复代码块(相似度 > 80%)

第 2 步:分类坏味道

按严重程度分类发现的问题:

等级含义说明
🔴 严重必须立即修复影响可维护性和稳定性
🟡 中等建议尽快修复降低代码可读性
🟢 轻微可择机优化不影响功能但有改进空间

第 3 步:优先级排序

按以下维度综合排序:

  1. 影响范围 — 被引用/调用次数越多,优先级越高
  2. 变更频率 — git log 频繁改动的文件优先
  3. 修复成本 — 成本低且收益高的优先处理

第 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天

## 注意事项
- 重构前确保有足够的测试覆盖
- 每次重构尽量小步提交,便于回滚
- 重构不应改变外部行为(行为保持)
- 大规模重构建议分阶段进行,每阶段独立可验证
- 关注重构过程中的性能回退风险

Similar Skills

claude-api
anthropics/skills180k

claude-api

Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).

Code quality & review

ponytail-review
DietrichGebert/ponytail158k

ponytail-review

Quality review of a change: is the logic right, is it safe, does it hold under real load, is risky code tested, is it fast enough, and is every line needed. Reads the connected code, not only the diff. Each finding is explained in plain English. Use for "review this", "code review", "review the last commit", "review my PR", "is this over-engineered", /ponytail-review.

Code quality & review

code-review-and-quality
addyosmani/agent-skills103k

code-review-and-quality

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

Code quality & review

documentation-and-adrs
addyosmani/agent-skills103k

documentation-and-adrs

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

Code quality & review

code-simplification
addyosmani/agent-skills103k

code-simplification

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

Code quality & review

understand
Egonex-AI/Understand-Anything86k

understand

Analyze a codebase to produce an interactive knowledge graph for understanding architecture, components, and relationships

Code quality & review