docs: 更新 AGENTS.md,添加测试工具和翻译文件结构说明

This commit is contained in:
雨霖铃
2026-05-25 19:15:31 +08:00
parent c98f767809
commit 61e741f198
+13 -1
View File
@@ -54,7 +54,7 @@ i18n/locales/{zh,en}/ # 国际化资源 (common.json, features.json 及各功
## 关键架构决策 ## 关键架构决策
**路由**: 不使用 React Router。通过 `config/features.tsx``FEATURES` 数组管理,`RouterProvider` 根据 `PageType` **路由**: 不使用 React Router。通过 `config/features.tsx``FEATURES` 数组管理,`RouterProvider` 根据 `PageType`
渲染对应组件。支持三种渲染模式: popup / sidepanel / tab。 渲染对应组件。支持三种渲染模式: popup / sidepanel / tab。每种模式有独立的路由和可见页面配置。
**存储**: 所有 Chrome Storage 键必须在 `types/storage.d.ts``StorageSchema` 中定义。使用 `utils/chromeStorage.ts` 及其 **存储**: 所有 Chrome Storage 键必须在 `types/storage.d.ts``StorageSchema` 中定义。使用 `utils/chromeStorage.ts` 及其
Hook。Router 同时使用 `chrome.storage.local``localStorage` 做快照以消除首屏闪烁。 Hook。Router 同时使用 `chrome.storage.local``localStorage` 做快照以消除首屏闪烁。
@@ -75,13 +75,20 @@ Hook。Router 同时使用 `chrome.storage.local` 和 `localStorage` 做快照
- `@/utils/useLazyTranslation` (返回 `ns:key` 格式翻译) - `@/utils/useLazyTranslation` (返回 `ns:key` 格式翻译)
- `window.matchMedia` - `window.matchMedia`
- 测试文件命名: `__tests__/*.test.{ts,tsx}``*.test.{ts,tsx}` - 测试文件命名: `__tests__/*.test.{ts,tsx}``*.test.{ts,tsx}`
- Mock 模式: 使用 `vi.mock()` 进行模块级 mock,避免在测试文件中重复 mock 代码
- 测试工具: `@testing-library/react` + `@testing-library/user-event` 进行组件测试
## i18n ## i18n
- 命名空间: `common` (默认), `features` - 命名空间: `common` (默认), `features`
- 翻译键格式: `namespace:key` (如 `features:timestamp.title`) - 翻译键格式: `namespace:key` (如 `features:timestamp.title`)
- 语言: `zh` (默认), `en` - 语言: `zh` (默认), `en`
- 翻译文件结构:
- `i18n/locales/{zh,en}/common.json` - 全局通用翻译
- `i18n/locales/{zh,en}/features.json` - 功能模块标题和描述
- `i18n/locales/{zh,en}/{功能名}.json` - 各功能独立翻译(如 timestamp.json, storageCleaner.json 等)
- 添加新翻译: 编辑 `i18n/locales/{zh,en}/{common,features}.json` 及对应功能独立 JSON - 添加新翻译: 编辑 `i18n/locales/{zh,en}/{common,features}.json` 及对应功能独立 JSON
- 使用 `useLazyTranslation` hook 加载功能独立翻译,返回 `ns:key` 格式
## 新功能开发清单 ## 新功能开发清单
@@ -97,6 +104,8 @@ Hook。Router 同时使用 `chrome.storage.local` 和 `localStorage` 做快照
- 禁止使用 `any` (测试文件除外) - 禁止使用 `any` (测试文件除外)
- 未使用变量/参数: 使用 `_` 前缀 (如 `_unused`) - 未使用变量/参数: 使用 `_` 前缀 (如 `_unused`)
- 样式: 使用 Tailwind CSS + shadcn/ui (通过 `className``cn()` 工具) - 样式: 使用 Tailwind CSS + shadcn/ui (通过 `className``cn()` 工具)
- UI 组件: 优先使用 `components/ui/` 下的 shadcn/ui 组件 (button, dialog, select 等)
- 图标: 使用 `lucide-react` 图标库
- 格式: Prettier (`.prettierrc`: 100 字符宽, 单引号, 尾逗号 all, LF 换行) - 格式: Prettier (`.prettierrc`: 100 字符宽, 单引号, 尾逗号 all, LF 换行)
- ESLint 使用 `typescript-eslint``projectService: true`(无需手动维护 project 路径) - ESLint 使用 `typescript-eslint``projectService: true`(无需手动维护 project 路径)
@@ -109,3 +118,6 @@ Hook。Router 同时使用 `chrome.storage.local` 和 `localStorage` 做快照
- TypeScript: ^5.9.3 - TypeScript: ^5.9.3
- Vitest: ^4.1.7 - Vitest: ^4.1.7
- i18next: ^26.2.0 - i18next: ^26.2.0
- @dnd-kit (拖拽排序)
- marked (Markdown 解析)
- qrious + qr-scanner (二维码生成与解析)