code-simplifier

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Simplifier

代码简化器

Enhance code clarity, consistency, and maintainability while preserving exact functionality. Apply project-specific best practices without altering behavior. Prioritize readable, explicit code over compact solutions.
Related Skills:
  • kavak-documentation
    - Query for Kavak coding standards and patterns before simplifying
  • Use
    kavak-platform/plati_query
    MCP tool to verify Kavak-specific idioms
提升代码的清晰度、一致性和可维护性,同时严格保留原有功能。应用项目特定的最佳实践,不改变代码行为。优先选择可读性强、表意明确的代码,而非紧凑的实现方案。
相关技能:
  • kavak-documentation
    - 在简化代码前查询Kavak编码标准与模式
  • 使用
    kavak-platform/plati_query
    MCP工具验证Kavak特定编码风格

Workflow

工作流程

1. Discover Project Standards

1. 发现项目标准

Locate project configuration files (in priority order):
  1. .claude/CLAUDE.md
    ,
    CLAUDE.md
    (root)
  2. .cursor/rules/*.md
    ,
    .cursor/rules/*.mdc
    ,
    .cursorrules
  3. AGENTS.md
    ,
    .github/copilot-instructions.md
  4. .editorconfig
    ,
    .prettierrc
    ,
    .eslintrc.*
Extract coding standards and patterns. If none exist, apply general best practices.
定位项目配置文件(按优先级排序):
  1. .claude/CLAUDE.md
    ,
    CLAUDE.md
    (根目录)
  2. .cursor/rules/*.md
    ,
    .cursor/rules/*.mdc
    ,
    .cursorrules
  3. AGENTS.md
    ,
    .github/copilot-instructions.md
  4. .editorconfig
    ,
    .prettierrc
    ,
    .eslintrc.*
提取编码标准与模式。若不存在相关文件,则应用通用最佳实践。

2. Identify Target Code

2. 确定目标代码

  • Default: Recently modified files (
    git diff
    ,
    git status
    )
  • Explicit: Files or directories specified by user
  • Broad: When instructed to review entire modules
  • 默认范围:最近修改的文件(
    git diff
    ,
    git status
  • 明确指定:用户指定的文件或目录
  • 宽泛范围:当要求审查整个模块时

3. Apply Refinements

3. 应用优化

Preserve Functionality
  • Never change what the code does, only how
  • Run existing tests to verify no regressions
Apply Project Standards
  • Follow discovered conventions
  • Match existing code style
  • Respect established patterns
Enhance Clarity
  • Reduce complexity and nesting
  • Eliminate redundant code
  • Use clear variable/function names
  • Avoid nested ternaries - use switch or if/else
  • Choose clarity over brevity
Maintain Balance
  • Don't create overly clever solutions
  • Don't combine too many concerns
  • Don't remove helpful abstractions
  • Three similar lines > premature abstraction
保留原有功能
  • 绝不改变代码的功能,仅优化实现方式
  • 运行现有测试以验证无回归问题
遵循项目标准
  • 遵循已发现的编码约定
  • 匹配现有代码风格
  • 尊重已确立的编码模式
提升清晰度
  • 降低复杂度与嵌套层级
  • 消除冗余代码
  • 使用清晰的变量/函数名称
  • 避免嵌套三元运算符 - 改用switch或if/else语句
  • 优先选择清晰度而非简洁性
保持平衡
  • 不要创造过于精巧的解决方案
  • 不要合并过多不同关注点的代码
  • 不要移除有用的抽象层
  • 三行相似代码 > 过早的抽象

4. Verify

4. 验证

  1. Functionality unchanged
  2. Code is simpler and maintainable
  3. Run linters/formatters if configured
  1. 功能未发生改变
  2. 代码更简洁且易于维护
  3. 若已配置,则运行代码检查工具/格式化工具

Guidelines

指导原则

  • Operate autonomously after code is written/modified
  • Don't add features or make "improvements" beyond simplification
  • Don't add docstrings/comments to unchanged code
  • Trust internal code and framework guarantees
  • 在代码编写或修改后自主运行
  • 除代码简化外,不要添加新功能或进行“改进”
  • 不要为未修改的代码添加文档字符串/注释
  • 信任内部代码与框架的可靠性

References

参考资料

ReferencePurpose
references/patterns.md
Common simplification patterns
references/anti-patterns.md
Code smells to refactor
references/examples.md
Before/after examples
参考资料用途
references/patterns.md
通用简化模式
references/anti-patterns.md
需要重构的代码异味
references/examples.md
优化前后的示例对比