/SKILL.md
# Code Analyzer Skill **版本**: 1.0.0 **作者**: sohot-gdjinni **标签**: `code-review`, `python`, `security`, `optimization` --- ## 简介 一个专业的 Python 代码分析与优化 Skill,提供: - 语法检查与结构分析 - 安全漏洞扫描 - 性能优化建议 - 重构后的可直接使用代码 --- ## 功能特性 | 功能 | 说明 | |------|------| | 🔍 **语法检查** | Python 语法验证、AST 结构分析 | | 🛡️ **安全扫描** | 检测硬编码密钥、裸 except、SQL 注入等 | | ⚡ **性能分析** | 识别低效循环、冗余计算、缓存机会 | | 📊 **代码质量** | 复杂度评估、重复代码检测 | | ✅ **修复版本** | 提供可直接使用的优化后代码 | --- ## 使用方法 ### 1. 直接分析代码 ```bash # 分析单个文件 python3 -m code_anal
npx skillsauth add sujian0606-cpu/code-analyzer-skill code-analyzer-skillInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
版本: 1.0.0
作者: sohot-gdjinni
标签: code-review, python, security, optimization
一个专业的 Python 代码分析与优化 Skill,提供:
| 功能 | 说明 | |------|------| | 🔍 语法检查 | Python 语法验证、AST 结构分析 | | 🛡️ 安全扫描 | 检测硬编码密钥、裸 except、SQL 注入等 | | ⚡ 性能分析 | 识别低效循环、冗余计算、缓存机会 | | 📊 代码质量 | 复杂度评估、重复代码检测 | | ✅ 修复版本 | 提供可直接使用的优化后代码 |
# 分析单个文件
python3 -m code_analyzer analyze /path/to/your/code.py
# 分析目录
python3 -m code_analyzer analyze /path/to/project/ --recursive
from code_analyzer import CodeAnalyzer
analyzer = CodeAnalyzer()
results = analyzer.analyze_file('your_code.py')
# 查看问题列表
for issue in results.issues:
print(f"[{issue.severity}] {issue.message}")
# 获取修复建议
fixed_code = results.get_fixed_code()
当你需要分析代码时,直接粘贴代码给我,我会:
def api_get(path):
import urllib.request
try:
req = urllib.request.Request('https://api.example.com' + path)
with urllib.request.urlopen(req) as resp:
return json.loads(resp.read())
except:
return None
📊 代码分析报告
==================================================
函数数量: 1
类数量: 0
导入语句: 1
🔍 发现的问题:
⚠️ [P0] 使用裸 except: 可能隐藏所有异常
⚠️ [P1] 硬编码 API 地址
⚠️ [P1] 缺少超时设置
⚠️ [P2] 导入语句在函数内
✅ 优化建议:
1. 使用具体的异常类型 (HTTPError, URLError)
2. 添加 timeout 参数
3. 将 import 移到文件顶部
import json
import urllib.request
import urllib.error
from typing import Optional, Dict
API_BASE_URL = 'https://api.example.com'
DEFAULT_TIMEOUT = 15
def api_get(path: str, timeout: int = DEFAULT_TIMEOUT) -> Optional[Dict]:
"""发送 GET 请求"""
try:
req = urllib.request.Request(API_BASE_URL + path)
with urllib.request.urlopen(req, timeout=timeout) as resp:
return json.loads(resp.read().decode('utf-8'))
except urllib.error.HTTPError as e:
print(f"HTTP错误: {e.code}")
return None
except urllib.error.URLError as e:
print(f"连接错误: {e.reason}")
return None
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
return None
except: 捕获所有异常# 克隆仓库
git clone https://github.com/yourusername/code-analyzer-skill.git
cd code-analyzer-skill
# 安装依赖
pip install -r requirements.txt
# 可选:安装为系统命令
pip install -e .
创建 .code_analyzer.yaml:
# 忽略的文件/目录
exclude:
- "*/venv/*"
- "*/__pycache__/*"
- "*/tests/*"
# 自定义规则
rules:
max_line_length: 120
max_function_lines: 50
max_complexity: 10
# 严重性覆盖
severity:
bare_except: "error" # 裸 except 升级为错误
missing_timeout: "warning" # 缺少超时降级为警告
┌─────────────────────────────────────────┐
│ 代码输入 │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 1. 语法检查 (AST解析) │
│ - Python 语法验证 │
│ - 结构分析 │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 2. 静态分析 │
│ - 安全扫描 │
│ - 性能检测 │
│ - 代码异味 │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 3. 问题分级 │
│ - P0/P1/P2/P3 │
│ - 影响评估 │
└─────────────────┬───────────────────────┘
▼
┌─────────────────────────────────────────┐
│ 4. 生成修复 │
│ - 代码重构 │
│ - 类型提示 │
│ - 文档生成 │
└─────────────────────────────────────────┘
欢迎贡献!请遵循以下流程:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)MIT License - 详见 LICENSE 文件
基于以下开源项目构建:
development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.