# 代码简化 (code-simplification)

> 在完全保持行为的前提下降低代码复杂度，让代码更易读、易改、易调试，而不是单纯减少行数。

- 分类: [重构](https://www.myskills.tools/zh/categories/refactoring/)
- 来源: 社区 · Addy Osmani
- 代码仓库: https://github.com/addyosmani/agent-skills/tree/main/skills/code-simplification (commit f1f6fbf)
- SKILL.md: https://github.com/addyosmani/agent-skills/blob/main/skills/code-simplification/SKILL.md
- 安装命令: `npx skills add addyosmani/agent-skills --skill code-simplification`
- 许可证: MIT
- 兼容工具: Claude Code, Codex, Cursor, Copilot, Gemini CLI
- 权限: read-repo ✓, write-files ✓, shell ✓, network ✗
- 状态: 扫描通过
- 规则扫描无法覆盖所有风险，安装前请阅读此技能的 SKILL.md，确认权限后再使用。

## 核心规则

严格保持行为不变；不确定某项简化是否保持行为时，就不要做。

## 执行阶段

1. **先理解再动手** — 遵循切斯特顿之篱：先弄清代码职责、调用关系、边界情况、相关测试和 git blame 中的背景，再做改动。
2. **识别简化点** — 按项目规范查找深层嵌套、过长函数、嵌套三元、含糊命名、重复逻辑、死代码和多余抽象。
3. **逐步应用** — 一次只做一项简化并运行测试，失败就回退；重构与功能或缺陷修复分开提交。
4. **整体验证** — 对比前后是否真的更易懂、与代码库一致；现有测试无需修改即通过，构建和 lint 无新问题。

## 权限说明（据 SKILL.md 整理）

| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 修改范围内的代码，默认为最近改动的部分。 |
| 命令执行 | 需要 | 运行测试、构建、lint 和 git blame，大规模改动时可使用 codemod 脚本。 |
| 网络外发 | 不需要 | 技能未要求访问网络。 |

## SKILL.md 头部信息（YAML）

```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.
---
```

首页: https://www.myskills.tools/zh/ · URL: https://www.myskills.tools/zh/skills/code-simplification/
