分享一个自用 code-style-review skill
之前分享了一个自用的 docx-format skill, 发现能帮到不少佬友。在此分享一个自己更常用的 SKILL:code-style-review. 原理是把我平常的代码风格沉淀下来作为 SKILL:绝对避免防御性编程、绝对避免复杂性编程。感兴趣的佬友们可以二次开发反馈~
贴一下 SKILL.md 文档:
---
name: code-style-review
description: Python code style guide for clean, maintainable code. Use when writing or reviewing Python code.
---
# Python Code Style Guide
## 必须 (Must)
### Naming
- Classes: `PascalCase` (e.g., `DataLoader`, `ConfigManager`)
- Functions/methods: `snake_case` with verb-first (e.g., `load_data`, `process_batch`)
- Constants: `UPPER_CASE` (e.g., `MAX_RETRIES`, `DEFAULT_TIMEOUT`)
- Math operations: single-letter variables allowed (N, D, x, y)
### Exception Handling
- Fail-fast: no defensive try/except, let errors crash early
- Use `logger.warning()` for recoverable issues, not exceptions
### Code Philosophy
- No over-engineering; keep it simple
- Comments in English only
- Follow Occam's Razor: no unnecessary complexity
## 尽量 (Should)
### Comments & Docs
- Minimal docstrings; only for complex logic
- Explain "why", not "what"
- Self-explanatory code needs no comments
### Imports
- Order: stdlib → third-party → local (blank lines between)
- Prefer absolute imports
- Explicit names, avoid `import *`
### Function Design
- Explicit parameters; avoid `**kwargs`
- Multiple returns: use tuple
- Avoid hidden global state
### Code Organization
- Layered architecture: low-level → high-level
- OOP for core logic
- Separation of concerns
### Aesthetics
- Clean alignment and simple naming
- Colorful output / progress bars for UX
- Use `logging` module
## 可选 (Optional)
### Type Annotations
- Python 3.10+ syntax: `list[int]`, `X | None`
- Annotate public methods and return types
### Assert
- Use sparingly for invariants; don't overuse
### Logging
- Optionally write logs to file (ask user first)
## 加分项 (Nice to Have)
### Data Structures
- Use `@dataclass` for configs
- Prefer simple containers (list, dict)
---
## Code Review (Codex)
All code review is delegated to Codex. Claude should NOT run scripts directly.
When invoking, Claude MUST replace placeholders with absolute paths:
- `{SKILL_DIR}` → absolute path to this skill directory (e.g., `/Users/xxx/.claude/skills/code-style-review`)
- `{TARGET}` → absolute path to file(s) or directory to review (supports multiple files or recursive directory scan)
```bash
codex exec -m gpt-5.2 \
-c model_reasoning_effort="xhigh" \
--dangerously-bypass-approvals-and-sandbox \
--skip-git-repo-check \
"You are a code style reviewer. Review the Python code for style compliance.
## Paths (absolute)
- Skill directory: {SKILL_DIR}
- Target to review: {TARGET}
## Setup (run once if tools missing)
bash {SKILL_DIR}/setup.sh
## Your Tasks
1. Read the style guide: cat {SKILL_DIR}/skill.md
2. Run automated linter: ruff check --config {SKILL_DIR}/ruff.toml {TARGET}
3. Run custom checker: python3 {SKILL_DIR}/style_check.py {TARGET}
4. Read and analyze the target code
5. Combine automated results with your own analysis
## Output Format
Provide a structured review:
- **Summary**: Overall assessment (pass/needs work/fail)
- **Automated Issues**: List violations from ruff and style_check.py
- **Manual Review**: Issues requiring human judgment (over-engineering, naming clarity, code aesthetics)
- **Suggestions**: Specific, actionable improvements with code examples
## Priority Levels
- 必须 (Must): Violations are errors, must fix
- 尽量 (Should): Violations are warnings, should fix
- 可选 (Optional): Suggestions for improvement
- 加分项 (Nice to Have): Optional enhancements" 2>/dev/null