refactoring-surgeon by erichowens/some_claude_skills
npx skills add https://github.com/erichowens/some_claude_skills --skill refactoring-surgeon专注于在不改变行为的前提下提升代码质量的专家级代码重构专家。
| 类别 | 技术 |
|---|---|
| 提取 | 提取方法、提取类、提取接口 |
| 移动 | 移动方法、移动字段、内联方法 |
| 简化 | 以多态取代条件表达式、分解条件表达式 |
| 组织 | 引入参数对象、以字面常量取代魔法数 |
| 遗留系统迁移 | 绞杀者模式、抽象分支、并行变更 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ 过长方法 │ │ 过大的类 │ │ 过长参数 │
│ > 20 行? │ │ > 200 行? │ │ 列表 │
│ → 提取方法 │ │ → 提取类 │ │ → 参数对象 │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ 分支语句 │ │ 被拒绝的遗赠 │ │ 平行 │
│ 类型检查? │ │ 未使用的继承? │ │ 继承体系 │
│ → 多态 │ │ → 委托 │ │ → 移动方法 │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐
│ 发散式变化 │ │ 霰弹式修改 │
│ 一个类,多个 │ │ 一次变更,多个 │
│ 变更原因? │ │ 类受影响? │
│ → 提取类 │ │ → 移动/内联 │
└─────────────────────┘ └─────────────────────┘
完整重构示例位于 ./references/:
| 文件 | 模式 | 用例 |
|---|---|---|
extract-method.ts | 提取方法 | 过长方法 → 功能聚焦的函数 |
replace-conditional-polymorphism.ts | 以多态取代条件表达式 | switch/if → 多态类 |
introduce-parameter-object.ts | 引入参数对象 | 过长参数 → 结构化对象 |
strangler-fig-pattern.ts | 绞杀者模式 | 遗留代码 → 渐进式迁移 |
症状:在一次大规模变更中重写整个模块 修复:采用绞杀者模式,进行小步、增量的变更并伴随测试
症状:在没有测试覆盖的情况下改变结构 修复:先编写特征测试,为受影响的区域增加覆盖率
症状:为“未来的灵活性”创建通用框架 修复:等待出现三个具体例子后再进行抽象(三则规则)
症状:查找替换操作遗漏了某些引用 修复:使用 IDE 的重构工具,先搜索所有使用处
症状:在结构调整的同时添加新功能 修复:分开提交 - 先重构,再添加功能
症状:难以审查的大型重构拉取请求 修复:提交小型、聚焦的拉取请求,并附上清晰的提交信息
症状:为一个简单操作设置三层抽象 修复:YAGNI(你不会需要它) - 从具体开始,当模式出现时再抽象
症状:开始了提取方法但留下了部分重复代码 修复:完成重构或回退 - 不要半途而废
症状:“我正好在这里,顺便清理一下...” 修复:绝不在故障期间重构 - 先修复错误,再创建工单
症状:重构后不知道是否有所帮助 修复:跟踪指标:复杂度、测试覆盖率、构建时间
重构前:
重构过程中:
重构后:
运行 ./scripts/validate-refactoring.sh 以检查:
每周安装量
98
仓库
GitHub 星标数
78
首次出现
Jan 24, 2026
安全审计
安装于
opencode84
codex83
cursor83
gemini-cli78
github-copilot76
claude-code75
Expert code refactoring specialist focused on improving code quality without changing behavior.
| Category | Techniques |
|---|---|
| Extraction | Extract Method, Extract Class, Extract Interface |
| Movement | Move Method, Move Field, Inline Method |
| Simplification | Replace Conditional with Polymorphism, Decompose Conditional |
| Organization | Introduce Parameter Object, Replace Magic Numbers |
| Legacy Migration | Strangler Fig, Branch by Abstraction, Parallel Change |
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ Long Method │ │ Large Class │ │ Long Parameter │
│ > 20 lines? │ │ > 200 lines? │ │ List │
│ → Extract Method │ │ → Extract Class │ │ → Parameter Object │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ Switch Statements │ │ Refused Bequest │ │ Parallel │
│ Type-checking? │ │ Unused inheritance?│ │ Hierarchies │
│ → Polymorphism │ │ → Delegation │ │ → Move Method │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐
│ Divergent Change │ │ Shotgun Surgery │
│ One class, many │ │ One change, many │
│ reasons to change? │ │ classes affected? │
│ → Extract Class │ │ → Move/Inline │
└─────────────────────┘ └─────────────────────┘
Complete refactoring examples in ./references/:
| File | Pattern | Use Case |
|---|---|---|
extract-method.ts | Extract Method | Long methods → focused functions |
replace-conditional-polymorphism.ts | Replace Conditional | switch/if → polymorphic classes |
introduce-parameter-object.ts | Parameter Object | Long params → structured objects |
strangler-fig-pattern.ts | Strangler Fig | Legacy code → gradual migration |
Symptom : Rewriting entire modules in one massive change Fix : Strangler fig pattern, small incremental changes with tests
Symptom : Changing structure without test coverage Fix : Write characterization tests first, add coverage for affected areas
Symptom : Creating generic frameworks "for future flexibility" Fix : Wait for three concrete examples before abstracting (Rule of Three)
Symptom : Find-and-replace that misses occurrences Fix : Use IDE refactoring tools, search for usages first
Symptom : Adding new functionality while restructuring Fix : Separate commits - refactor first, then add features
Symptom : Large refactoring PRs that are hard to review Fix : Small, focused PRs with clear commit messages
Symptom : Three layers of abstraction for a simple operation Fix : YAGNI - start concrete, abstract when patterns emerge
Symptom : Starting Extract Method but leaving partial duplication Fix : Complete the refactoring or revert - no half-measures
Symptom : "I'll just clean this up while I'm here..." Fix : Never refactor during incidents - fix the bug, create a ticket
Symptom : Refactoring without knowing if it helped Fix : Track metrics: complexity, test coverage, build time
Before Refactoring:
During Refactoring:
After Refactoring:
Run ./scripts/validate-refactoring.sh to check:
Weekly Installs
98
Repository
GitHub Stars
78
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode84
codex83
cursor83
gemini-cli78
github-copilot76
claude-code75
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装