refactoring by dmitryprg-ai/cursor-develop-autorules
npx skills add https://github.com/dmitryprg-ai/cursor-develop-autorules --skill refactoring原则:改变结构,而非行为。
如果行为发生改变,那就不是重构——而是功能开发或错误修复。
| 何时重构 | 何时不应重构 |
|---|---|
| 代码能工作但难以理解 | 代码尚不能工作 |
| 存在重复代码 | 没有测试存在 |
| 方法过长(> 50 行) | 时间紧迫 |
| 嵌套过深(> 3 层) | "仅仅因为想重构" |
1. 验证 -> 所有测试通过
2. 识别 -> 确定要重构的内容
3. 预规划 -> 检查文件大小限制(standard-file-size-limits 规则)
4. 规划 -> 规划小步骤
5. 执行 -> 执行一个步骤
6. 测试 -> 步骤后运行测试
7. 提交 -> 如果测试通过则提交
8. 重复 -> 进行下一步
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 代码异味 | 重构方法 |
|---|
| 方法过长(> 50 行) | 提取方法 |
| 重复代码 | 提取方法/类 |
| 参数列表过长(> 4) | 参数对象 |
| 嵌套过深(> 3 层) | 卫语句 |
| 魔法数字 | 提取常量 |
每周安装数
1
代码仓库
GitHub 星标数
5
首次出现
1 天前
安全审计
安装于
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
Principle: CHANGE STRUCTURE, NOT BEHAVIOR.
If behavior changes, it's NOT refactoring -- it's a feature or bugfix.
| Refactor When | Do NOT When |
|---|---|
| Code works but hard to understand | Code doesn't work yet |
| Duplicated code | No tests exist |
| Long methods (> 50 lines) | Under time pressure |
| Deep nesting (> 3 levels) | "Just because" |
1. VERIFY -> All tests pass
2. IDENTIFY -> What to refactor
3. PREPLAN -> Check file size limits (standard-file-size-limits rule)
4. PLAN -> Small steps
5. EXECUTE -> One step
6. TEST -> Tests after step
7. COMMIT -> Commit if green
8. REPEAT -> Next step
| Code Smell | Refactoring |
|---|---|
| Long Method (> 50 lines) | Extract Method |
| Duplicate Code | Extract Method/Class |
| Long Parameter List (> 4) | Parameter Object |
| Deep Nesting (> 3 levels) | Guard Clauses |
| Magic Numbers | Extract Constant |
Weekly Installs
1
Repository
GitHub Stars
5
First Seen
1 day ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装