code-simplificationcommit f1f6fbfSKILL.md · 重构
代码简化
在完全保持行为的前提下降低代码复杂度,让代码更易读、易改、易调试,而不是单纯减少行数。
npx skills add addyosmani/agent-skills --skill code-simplification已选中命令,请手动复制。
- 权限
- read-repo
- write-files
- shell
- network
- 兼容工具
- Claude Code, Codex, Cursor, Copilot, Gemini CLI
- GitHub
- 112.3k
- 来源
- 社区 · Addy Osmani
- 状态
- 扫描通过
- 许可证
- MIT
- 分类
- 重构
核心规则
严格保持行为不变;不确定某项简化是否保持行为时,就不要做。
执行阶段
阶段 01先理解再动手
遵循切斯特顿之篱:先弄清代码职责、调用关系、边界情况、相关测试和 git blame 中的背景,再做改动。
阶段 02识别简化点
按项目规范查找深层嵌套、过长函数、嵌套三元、含糊命名、重复逻辑、死代码和多余抽象。
阶段 03逐步应用
一次只做一项简化并运行测试,失败就回退;重构与功能或缺陷修复分开提交。
阶段 04整体验证
对比前后是否真的更易懂、与代码库一致;现有测试无需修改即通过,构建和 lint 无新问题。
权限说明(据 SKILL.md 整理)
| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 修改范围内的代码,默认为最近改动的部分。 |
| 命令执行 | 需要 | 运行测试、构建、lint 和 git blame,大规模改动时可使用 codemod 脚本。 |
| 网络外发 | 不需要 | 技能未要求访问网络。 |
SKILL.md 头部信息(YAML)
---
name: code-simplification
description: 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. Use when asked to simplify, clean up, or reduce the nesting of a function or module that already works, even when the code is pasted inline and nothing else needs to change.
---相关技能
规则扫描无法覆盖所有风险,安装前请阅读此技能的 SKILL.md,确认权限后再使用。