← 返回 Skills 市场
aqbjqtd

Code Simplifier

作者 sniper-one · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ✓ 安全检测通过
624
总下载
0
收藏
5
当前安装
3
版本数
在 OpenClaw 中安装
/install code-simplifier
功能描述
当用户要求简化代码、重构代码、优化代码、改进代码质量时使用此技能。提供代码简化原则和最佳实践指导,确保代码符合质量标准。
使用说明 (SKILL.md)

Code Simplifier

提供代码简化、重构和优化的原则指导。

核心原则

函数设计

  • 单一职责: 每个函数只做一件事
  • 长度控制: 目标 \x3C 50 行,理想 10-30 行
  • 参数控制: ≤ 4 个参数;超过时使用数据类或配置对象
  • 早期返回: 用 guard clauses 避免深层嵌套

代码组织

  • DRY: 提取重复逻辑为公共函数
  • 命名清晰: 变量名反映意图,避免单字母(循环变量除外)
  • 无魔法数字: 提取为命名常量
  • 嵌套控制: 嵌套层级 ≤ 3 层

错误处理

  • 捕获具体异常,不使用裸 except:
  • 保留原始异常链 (raise ... from e)
  • 使用 context manager 管理资源

语言特定规范

Python

# ✅ 类型注解
def process(user_id: int, data: dict) -> dict | None:
    ...

# ✅ list/dict comprehension(避免嵌套)
result = [x for x in items if x.condition]

# ✅ 命名
snake_case(变量/函数), PascalCase(类), UPPER_SNAKE_CASE(常量)

# ❌ 避免
# - 嵌套 comprehension
# - 过度使用 lambda
# - 裸 except:

JavaScript / TypeScript

// ✅ const/let,无 var
// ✅ 箭头函数
const process = (data) => data.filter(x => x.valid);

// ✅ 解构
const { name, email } = user;

// ✅ 命名
camelCase(变量/函数), PascalCase(类/接口), UPPER_SNAKE_CASE(常量)

自动化工具

命令行分析工具

python scripts/code_simplifier.py \x3Cfile.py> --analyze        # 分析复杂度
python scripts/code_simplifier.py \x3Cfile.py> --suggest       # 生成重构建议
python scripts/code_simplifier.py \x3Cfile.py> --simplify      # 自动简化代码
python scripts/code_simplifier.py \x3Cfile.py> --output=out.py # 指定输出文件

输出格式支持 text(默认)和 json

质量检查清单

函数级别

  • 函数长度 \x3C 50 行
  • 嵌套层级 \x3C 3 层
  • 单一职责
  • 命名有意义

代码级别

  • 无重复代码
  • 无魔法数字
  • 无未使用变量/导入
  • 错误处理具体

整体质量

  • 符合语言规范
  • 类型注解/标注完整
  • 可读性良好
  • 易于维护

前端编码规范(网页项目必须遵守)

  1. HTML 安全:所有动态内容用 textContent 赋值,禁止 innerHTML;必须用 escapeHTML() 转义 \x3C > & ' "
  2. 移动端兼容:按钮 touch-action: manipulation,点击目标 ≥44px
  3. CSS 布局:用 Flexbox/Grid,不用 float
  4. 响应式:相对单位(rem/em/%),viewport meta tag
  5. 性能:LCP \x3C 2.5s、INP \x3C 200ms、CLS \x3C 0.1

修复阶段加载 web-fixing 技能诊断;编码阶段遵守以上 5 条即可预防大部分问题。

参考文档

  • 重构模式: refactoring_patterns.md — Early Return、Extract Method、Guard Clauses、Async/Await 等 20+ 模式
  • 最佳实践: best-practices.md — 函数设计、代码组织、错误处理、性能优化、测试友好设计
  • 故障排除: troubleshooting.md — 代码异味诊断、复杂度分析、自动化工具、重构工作流
安全使用建议
This skill appears coherent and local: it analyzes code via AST and offers refactoring suggestions. Before installing or running, review the full scripts (scripts/code_simplifier.py) yourself for any unexpected imports or network/socket/subprocess calls (search for requests, socket, subprocess, os.system, urllib, http, ftplib) — the provided excerpts show only local analysis. When running against untrusted code, use a sandbox or run on a copy (the tool reads files you pass it). If you need networked features later, require explicit documentation and minimal, well-justified credentials.
功能分析
Type: OpenClaw Skill Name: code-simplifier Version: 1.1.1 The bundle is a legitimate tool for code analysis and refactoring. The core logic in `scripts/code_simplifier.py` uses Python's `ast` module for safe static analysis of code complexity and regex for pattern matching, without using dangerous functions like `eval()` or performing unauthorized network/file operations. The instructions in `SKILL.md` and the supporting documentation in the `references/` directory provide standard software engineering best practices and lack any signs of prompt injection or malicious intent.
能力评估
Purpose & Capability
Name/description (code simplification, refactoring guidance) match the provided SKILL.md, reference docs, and the included Python script that analyzes and suggests refactors. No unrelated binaries, env vars, or config paths are requested.
Instruction Scope
SKILL.md is focused on coding best-practices and tells the agent to run the bundled CLI script (python scripts/code_simplifier.py) on user-provided files and produce analysis/suggestions. The instructions only reference analyzing files the user passes and producing text/json output — no guidance to read system-wide secrets, shell history, or exfiltrate results to external endpoints.
Install Mechanism
No install spec is provided (instruction-only with an included script). The script appears to be a local AST-based analyzer; there are no downloads or archive extraction steps. The SKILL.md mentions third-party tools (radon, black, pylint) as optional tooling but does not attempt to install arbitrary remote code.
Credentials
The skill requests no environment variables, credentials, or config paths. The content includes examples referencing common developer libs (e.g., an import example that mentions OpenAI) only in documentation; there are no declared secrets or credential needs that are disproportionate to a refactoring tool.
Persistence & Privilege
always is false and the skill does not request persistent or elevated privileges. It does not modify other skills' configs or system-wide settings based on the provided materials.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install code-simplifier
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /code-simplifier 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.1
- Added documentation for a command-line code analysis and simplification tool, including usage examples and output formats. - Introduced mandatory front-end coding standards for web projects, covering HTML safety, mobile compatibility, CSS layout, responsiveness, and performance metrics. - Removed example/demo and script test files from the project. - Updated references and best practices documentation to reflect new guidance and tools.
v1.1.0
- Added usage examples and testing scripts to demonstrate and validate the skill (examples/demo_usage.py, scripts/test_simplifier.py). - Updated best practices and core documentation for improved clarity (SKILL.md, references/best-practices.md). - Removed the section on command-line analysis tools from the main documentation.
v1.0.0
Initial release with code analysis, refactoring suggestions, and simplification tools
元数据
Slug code-simplifier
版本 1.1.1
许可证 MIT-0
累计安装 5
当前安装数 5
历史版本数 3
常见问题

Code Simplifier 是什么?

当用户要求简化代码、重构代码、优化代码、改进代码质量时使用此技能。提供代码简化原则和最佳实践指导,确保代码符合质量标准。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 624 次。

如何安装 Code Simplifier?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install code-simplifier」即可一键安装,无需额外配置。

Code Simplifier 是免费的吗?

是的,Code Simplifier 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Code Simplifier 支持哪些平台?

Code Simplifier 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Code Simplifier?

由 sniper-one(@aqbjqtd)开发并维护,当前版本 v1.1.1。

💬 留言讨论