mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-31 22:23:27 +08:00
Revert "feat(ecc): prune plugin 43→12 items, promote 7 rules to .claude/rules/ (#245)"
This reverts commit 1bd68ff534.
This commit is contained in:
37
docs/zh-CN/rules/python/coding-style.md
Normal file
37
docs/zh-CN/rules/python/coding-style.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Python 编码风格
|
||||
|
||||
> 本文件在 [common/coding-style.md](../common/coding-style.md) 的基础上扩展了 Python 特定的内容。
|
||||
|
||||
## 标准
|
||||
|
||||
* 遵循 **PEP 8** 规范
|
||||
* 在所有函数签名上使用 **类型注解**
|
||||
|
||||
## 不变性
|
||||
|
||||
优先使用不可变数据结构:
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class User:
|
||||
name: str
|
||||
email: str
|
||||
|
||||
from typing import NamedTuple
|
||||
|
||||
class Point(NamedTuple):
|
||||
x: float
|
||||
y: float
|
||||
```
|
||||
|
||||
## 格式化
|
||||
|
||||
* 使用 **black** 进行代码格式化
|
||||
* 使用 **isort** 进行导入排序
|
||||
* 使用 **ruff** 进行代码检查
|
||||
|
||||
## 参考
|
||||
|
||||
查看技能:`python-patterns` 以获取全面的 Python 惯用法和模式。
|
||||
14
docs/zh-CN/rules/python/hooks.md
Normal file
14
docs/zh-CN/rules/python/hooks.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Python 钩子
|
||||
|
||||
> 本文档扩展了 [common/hooks.md](../common/hooks.md) 中关于 Python 的特定内容。
|
||||
|
||||
## PostToolUse 钩子
|
||||
|
||||
在 `~/.claude/settings.json` 中配置:
|
||||
|
||||
* **black/ruff**:编辑后自动格式化 `.py` 文件
|
||||
* **mypy/pyright**:编辑 `.py` 文件后运行类型检查
|
||||
|
||||
## 警告
|
||||
|
||||
* 对编辑文件中的 `print()` 语句发出警告(应使用 `logging` 模块替代)
|
||||
34
docs/zh-CN/rules/python/patterns.md
Normal file
34
docs/zh-CN/rules/python/patterns.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Python 模式
|
||||
|
||||
> 本文档扩展了 [common/patterns.md](../common/patterns.md),补充了 Python 特定的内容。
|
||||
|
||||
## 协议(鸭子类型)
|
||||
|
||||
```python
|
||||
from typing import Protocol
|
||||
|
||||
class Repository(Protocol):
|
||||
def find_by_id(self, id: str) -> dict | None: ...
|
||||
def save(self, entity: dict) -> dict: ...
|
||||
```
|
||||
|
||||
## 数据类作为 DTO
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class CreateUserRequest:
|
||||
name: str
|
||||
email: str
|
||||
age: int | None = None
|
||||
```
|
||||
|
||||
## 上下文管理器与生成器
|
||||
|
||||
* 使用上下文管理器(`with` 语句)进行资源管理
|
||||
* 使用生成器进行惰性求值和内存高效迭代
|
||||
|
||||
## 参考
|
||||
|
||||
查看技能:`python-patterns`,了解包括装饰器、并发和包组织在内的综合模式。
|
||||
25
docs/zh-CN/rules/python/security.md
Normal file
25
docs/zh-CN/rules/python/security.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Python 安全
|
||||
|
||||
> 本文档基于 [通用安全指南](../common/security.md) 扩展,补充了 Python 相关的内容。
|
||||
|
||||
## 密钥管理
|
||||
|
||||
```python
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
api_key = os.environ["OPENAI_API_KEY"] # Raises KeyError if missing
|
||||
```
|
||||
|
||||
## 安全扫描
|
||||
|
||||
* 使用 **bandit** 进行静态安全分析:
|
||||
```bash
|
||||
bandit -r src/
|
||||
```
|
||||
|
||||
## 参考
|
||||
|
||||
查看技能:`django-security` 以获取 Django 特定的安全指南(如适用)。
|
||||
33
docs/zh-CN/rules/python/testing.md
Normal file
33
docs/zh-CN/rules/python/testing.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Python 测试
|
||||
|
||||
> 本文件在 [通用/测试.md](../common/testing.md) 的基础上扩展了 Python 特定的内容。
|
||||
|
||||
## 框架
|
||||
|
||||
使用 **pytest** 作为测试框架。
|
||||
|
||||
## 覆盖率
|
||||
|
||||
```bash
|
||||
pytest --cov=src --cov-report=term-missing
|
||||
```
|
||||
|
||||
## 测试组织
|
||||
|
||||
使用 `pytest.mark` 进行测试分类:
|
||||
|
||||
```python
|
||||
import pytest
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_calculate_total():
|
||||
...
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_database_connection():
|
||||
...
|
||||
```
|
||||
|
||||
## 参考
|
||||
|
||||
查看技能:`python-testing` 以获取详细的 pytest 模式和夹具信息。
|
||||
Reference in New Issue
Block a user