From 7e4c61e6e9f135a6f63fd32b35dfea35f6b87c02 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 16 Apr 2026 15:58:28 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9E=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=AD=97=E6=AE=B5=E8=A7=84=E8=8C=83=E5=8F=8A?= =?UTF-8?q?=20Code=20Review=20=E6=A3=80=E6=9F=A5=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sisyphus --- CLAUDE.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index d14e7d7..acabfcc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -113,6 +113,24 @@ Handler → Service → Store → Model - 禁止硬编码字符串和 magic numbers - **必须为所有常量添加中文注释** +### 枚举与状态字段(必须遵守) + +**两个强制规则**: + +1. **int vs string**:状态类(生命周期)用 `int`,类型/方式类用 `string` +2. **DTO description 必须从 constants 原文抄写**,禁止凭记忆填写枚举值(历史上已有 description 与 constants 不一致导致前端显示错误的案例) + +```go +// ✅ description 从 constants 原文抄,格式统一用冒号+逗号 +Status int `json:"status" description:"状态 (1:待支付, 2:已支付, 3:已完成, 4:已关闭, 5:已退款)"` +StatusName string `json:"status_name" description:"状态名称(中文)"` // Response DTO 必须加 + +// ❌ 禁止:启用/禁用用 1=启用 2=禁用(全局约定是 0=禁用, 1=启用) +// ❌ 禁止:description 枚举值与 constants 不一致 +``` + +**完整规范**: 参见 [`docs/enum-status-standards.md`](docs/enum-status-standards.md) + ### 注释规范 - **所有注释使用中文**,导出符号必须有文档注释(包、函数、类型、接口、常量) @@ -220,6 +238,13 @@ Handler → Service → Store → Model - [ ] 常量定义在 `pkg/constants/` - [ ] 使用 Go 惯用法(非 Java 风格) +### 枚举与状态 + +- [ ] 状态类字段用 `int`,类型/方式类字段用 `string` +- [ ] 禁用/启用使用 `0=禁用, 1=启用`(禁止 `1=启用, 2=禁用`) +- [ ] DTO description 枚举列表已从 `pkg/constants/` 原文抄写,无遗漏、无错误 +- [ ] Response DTO 的 int 状态字段有对应的 `_name` 文字字段 + ### 文档和注释 - [ ] 所有注释使用中文