code-simplifier
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Simplifier
代码简化工具
Refine code so it is easier to read, reason about, and maintain without changing what it does.
Source basis: adapted from Anthropic's skill:
code-simplifierhttps://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.md优化代码使其更易于阅读、理解和维护,同时不改变其功能。
来源基础:改编自Anthropic的技能:
code-simplifierhttps://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.mdCore Rules
核心规则
- Preserve functionality exactly.
- Keep public behavior, outputs, side effects, and interfaces unchanged.
- Follow project-specific coding standards and patterns.
- Prefer clarity over compactness.
- Avoid clever rewrites that reduce debuggability.
- 完全保留原有功能。
- 保持公开行为、输出、副作用和接口不变。
- 遵循项目特定的编码标准和模式。
- 优先考虑清晰度而非简洁性。
- 避免采用会降低可调试性的巧妙重写。
Simplification Targets
简化目标
Improve code by:
- Reducing unnecessary nesting and branching complexity.
- Removing redundant abstractions and duplicate logic.
- Renaming unclear identifiers to improve intent readability.
- Splitting dense logic into coherent, single-purpose helpers.
- Replacing fragile one-liners with explicit, readable control flow.
- Removing comments that only restate obvious code behavior.
Prefer explicit conditionals over nested ternaries for multi-branch logic.
通过以下方式改进代码:
- 减少不必要的嵌套和分支复杂度。
- 移除冗余的抽象和重复逻辑。
- 重命名不清晰的标识符以提升意图可读性。
- 将复杂逻辑拆分为连贯的、单一用途的辅助函数。
- 用明确、易读的控制流替换脆弱的单行代码。
- 删除仅重复明显代码行为的注释。
对于多分支逻辑,优先使用显式条件语句而非嵌套三元运算符。
Boundaries
边界限制
Do not:
- Change business logic or edge-case behavior.
- Alter API contracts, data formats, or error semantics unless requested.
- Expand scope beyond recently touched code unless explicitly requested.
- Over-normalize style at the expense of local codebase conventions.
请勿:
- 更改业务逻辑或边缘情况行为。
- 修改API契约、数据格式或错误语义,除非有明确要求。
- 超出当前任务中涉及的代码范围,除非有明确要求。
- 为了过度统一风格而牺牲本地代码库的约定。
Workflow
工作流程
- Identify files and sections changed in the current task.
- Detect readability and maintainability issues in that scope.
- Apply minimal, behavior-preserving refactors.
- Re-check for regressions in logic, interfaces, and side effects.
- Run available lint/test checks when practical.
- Summarize only meaningful structural changes.
- 识别当前任务中已更改的文件和代码段。
- 检测该范围内的可读性和可维护性问题。
- 应用最小化的、保留行为的重构。
- 重新检查逻辑、接口和副作用是否存在回归问题。
- 尽可能运行可用的代码检查/测试。
- 仅总结有意义的结构性变更。
Decision Heuristics
决策准则
- If two versions are equivalent, choose the one a new teammate can understand fastest.
- Keep useful abstractions; remove only those that add indirection without value.
- Prefer straightforward flow over reduced line count.
- Stop when readability gains flatten out.
- 如果两个版本功能等效,选择新团队成员能最快理解的版本。
- 保留有用的抽象;仅移除那些只会增加间接性而无价值的抽象。
- 优先选择直观的代码流程而非减少代码行数。
- 当可读性提升不再明显时停止优化。