← 返回 Skills 市场
ksky521

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality.

作者 三水清 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
155
总下载
0
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install code-smell-analyzer
功能描述
Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestio...
使用说明 (SKILL.md)

Code Smell Analyzer

Analyzes code files for potential improvements including code smells, design patterns, and best practices. Provides suggestions for enhancing readability, maintainability, and performance while preserving functionality.

When to Use

Invoke this skill when:

  • User asks for code analysis or code review
  • User wants suggestions to improve code quality
  • User mentions "code smells", "refactoring", or "best practices"
  • User wants to optimize code structure without changing functionality

Analysis Framework

1. Code Smells

Identify any code smells such as:

  • Long Methods: Methods exceeding 20-30 lines should be broken down
  • Large Classes: Classes with too many responsibilities
  • Duplicate Code: Repeated code blocks that should be extracted
  • Complex Conditionals: Deeply nested if/else statements
  • Magic Numbers: Hard-coded values without explanation
  • Dead Code: Unused variables, methods, or imports
  • Long Parameter Lists: Methods with more than 3-4 parameters
  • Feature Envy: Methods that use another class more than their own

2. Design Patterns

Suggest appropriate design patterns that could improve the code structure:

  • Creational: Factory, Builder, Singleton, Prototype
  • Structural: Adapter, Decorator, Facade, Composite
  • Behavioral: Strategy, Observer, Command, State, Template Method

3. Best Practices

Check adherence to language-specific best practices:

  • Naming Conventions: Clear, descriptive names for variables, functions, classes
  • DRY Principle: Don't Repeat Yourself
  • SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
  • Error Handling: Proper exception handling and error messages
  • Documentation: Adequate comments and documentation
  • Testing: Testability of the code

4. Readability

Evaluate code clarity:

  • Naming: Are names self-documenting?
  • Structure: Is the code well-organized?
  • Comments: Are complex sections explained?
  • Formatting: Is indentation and spacing consistent?
  • Abstraction Level: Is the code at the right level of abstraction?

5. Maintainability

Assess how easy the code would be to modify and extend:

  • Coupling: Are components loosely coupled?
  • Cohesion: Are related functionalities grouped together?
  • Modularity: Can parts be changed independently?
  • Configuration: Are hard-coded values externalized?
  • Logging: Is there adequate logging for debugging?

6. Performance

Identify potential performance optimizations:

  • Algorithm Complexity: O(n) vs O(n^2) considerations
  • Memory Usage: Unnecessary object creation, memory leaks
  • I/O Operations: Database queries, file operations, network calls
  • Caching: Opportunities for caching repeated computations
  • Lazy Loading: Defer expensive operations until needed

Output Format

For each suggestion, provide:

Issue Description

Clear explanation of the issue or improvement opportunity.

Current Code

// Show the problematic code

Suggested Improvement

// Show the improved code

Rationale

Explain why the change would be beneficial.

Priority

  • High: Critical issues affecting functionality, security, or major performance
  • Medium: Important improvements for maintainability and readability
  • Low: Minor enhancements or nice-to-have improvements

Example Analysis

Issue: Long Method with Multiple Responsibilities

Priority: High

Current Code:

function processOrder(order) {
    // Validate order
    if (!order.items || order.items.length === 0) {
        throw new Error('Order has no items');
    }
    if (!order.customer) {
        throw new Error('Customer is required');
    }

    // Calculate totals
    let subtotal = 0;
    for (const item of order.items) {
        subtotal += item.price * item.quantity;
    }
    const tax = subtotal * 0.1;
    const total = subtotal + tax;

    // Apply discount
    if (order.discountCode) {
        total = total * 0.9;
    }

    // Save to database
    db.orders.insert({
        ...order,
        subtotal,
        tax,
        total,
        createdAt: new Date(),
    });

    // Send confirmation email
    emailService.send(order.customer.email, 'Order Confirmed', total);

    return {orderId: order.id, total};
}

Suggested Improvement:

function processOrder(order) {
    validateOrder(order);
    const pricing = calculatePricing(order);
    saveOrder(order, pricing);
    sendConfirmation(order, pricing.total);
    return {orderId: order.id, total: pricing.total};
}

function validateOrder(order) {
    if (!order.items?.length) throw new Error('Order has no items');
    if (!order.customer) throw new Error('Customer is required');
}

function calculatePricing(order) {
    const subtotal = order.items.reduce((sum, item) => sum + item.price * item.quantity, 0);
    const tax = subtotal * 0.1;
    let total = subtotal + tax;

    if (order.discountCode) {
        total *= 0.9;
    }

    return {subtotal, tax, total};
}

function saveOrder(order, pricing) {
    db.orders.insert({
        ...order,
        ...pricing,
        createdAt: new Date(),
    });
}

function sendConfirmation(order, total) {
    emailService.send(order.customer.email, 'Order Confirmed', total);
}

Rationale:

  • Single Responsibility: Each function has one clear purpose
  • Testability: Each function can be tested independently
  • Readability: Main function reads like a high-level overview
  • Maintainability: Changes to pricing logic don't affect validation

Language-Specific Considerations

JavaScript/TypeScript

  • Use const/let instead of var
  • Prefer arrow functions for callbacks
  • Use optional chaining (?.) and nullish coalescing (??)
  • Avoid any type in TypeScript

Python

  • Follow PEP 8 style guide
  • Use list comprehensions appropriately
  • Leverage context managers (with statements)
  • Type hints for better documentation

Java

  • Use streams for collection operations
  • Prefer composition over inheritance
  • Use Optional instead of null
  • Follow Java naming conventions

WeChat Mini Program

  • Use Service layer for all HTTP requests
  • Avoid storing redundant data in Page data
  • Use wx:key for list rendering
  • Follow the project's AGENTS.md guidelines

Notes

  • Always preserve existing functionality
  • Consider the project's existing conventions
  • Prioritize changes by impact and effort
  • Provide actionable, specific suggestions
  • Consider backward compatibility
安全使用建议
This skill appears coherent and low-risk because it is instruction-only and asks for no secrets or installs. Before using, avoid pasting sensitive or proprietary code (API keys, credentials, or private data) into the chat; verify any suggested code changes before applying them; and if you need an offline or audited review for sensitive projects, prefer a local tool or human reviewer. If you want assurance that no code is ever transmitted externally, confirm platform-level data-handling policies — the SKILL.md itself does not specify network calls.
功能分析
Type: OpenClaw Skill Name: code-smell-analyzer Version: 1.0.0 The skill bundle contains standard instructions for an AI agent to perform code quality analysis and refactoring suggestions. The content in SKILL.md is purely instructional and aligns with the stated purpose of identifying code smells and design patterns without any evidence of malicious intent or data exfiltration.
能力评估
Purpose & Capability
The name/description (code-smell analysis, design patterns, best practices) match the SKILL.md content. The skill does not request unrelated binaries, environment variables, or config paths.
Instruction Scope
The SKILL.md contains guidance for analyzing code and an output format for suggestions. It does not instruct the agent to read system files, access environment variables, transmit code to external endpoints, or perform any operations outside reviewing user-provided code. Example snippets reference typical application calls but are illustrative only.
Install Mechanism
There is no install specification and no code files — this is instruction-only, so nothing will be written to disk or downloaded during install.
Credentials
No environment variables, credentials, or config paths are required. The skill's declared needs are minimal and appropriate for a code-review helper.
Persistence & Privilege
The skill is not forced-always; it is user-invocable and uses the platform default for model invocation. It does not request or imply persistent system-wide privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install code-smell-analyzer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /code-smell-analyzer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Major simplification and rewrite of skill focus. - Deep DDD architecture and advanced code structure analysis (previously described) has been removed. - All scripts for automatic deep analysis and CLI usage are removed. - New version provides a general framework for identifying code smells, suggesting design patterns, and applying best coding practices across languages. - Now designed to give actionable suggestions for code maintainability, readability, and performance when users request code analysis or review. - Usage documentation, sample outputs, and best practices are streamlined and generalized.
元数据
Slug code-smell-analyzer
版本 1.0.0
许可证 MIT-0
累计安装 2
当前安装数 2
历史版本数 1
常见问题

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality. 是什么?

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestio... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 155 次。

如何安装 Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality.?

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

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality. 是免费的吗?

是的,Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality. 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality. 支持哪些平台?

Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality. 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Analyzes code for improvements including code smells, design patterns, and best practices. Invoke when user asks for code analysis, code review, or suggestions to improve code quality.?

由 三水清(@ksky521)开发并维护,当前版本 v1.0.0。

💬 留言讨论