docs: 统一规范文档示例格式,使用三级标题 Example 和四级标题 Good/Bad 展示代码示例

This commit is contained in:
Lyda
2026-04-13 13:00:57 +08:00
parent dae54e90b6
commit f34b31f542
8 changed files with 141 additions and 71 deletions
+36 -18
View File
@@ -16,7 +16,9 @@
- 每个模块的目录下可以包含 `interceptor` 目录,用于存放拦截器
- 每个模块的目录下可以包含 `filter` 目录,用于存放异常过滤器
### Good
### Example: 目录结构
#### Good: 按模块组织的目录结构
```txt
src/
@@ -43,7 +45,7 @@ src/
└── main.ts # 应用入口
```
### Bad
#### Bad: 扁平化的目录结构
```txt
src/
@@ -63,13 +65,15 @@ src/
- 文件名必须加 `.controller.ts` 后缀
- 注解和装饰器上的静态值无需进行魔法值的提炼 `[JsTs.Base.NoMagicStringsAndNumbers]`
### Good
### Example: 控制器文件命名
#### Good: 使用小写加横线命名
```txt
user-extends.controller.ts
```
### Bad
#### Bad: 使用大驼峰命名
```txt
userController.ts
@@ -83,13 +87,15 @@ userController.ts
- 文件名使用小写加横线命名(如 `user-extends.service.ts`
- 文件名必须加 `.service.ts` 后缀
### Good
### Example: 服务文件命名
#### Good: 使用小写加横线命名
```txt
user-extends.service.ts
```
### Bad
#### Bad: 使用大驼峰命名
```txt
userService.ts
@@ -100,13 +106,15 @@ userService.ts
- 文件名使用小写加横线命名(如 `user-extends.module.ts`
- 文件名必须加 `.module.ts` 后缀
### Good
### Example: 模块文件命名
#### Good: 使用小写加横线命名
```txt
user-extends.module.ts
```
### Bad
#### Bad: 使用大驼峰命名
```txt
userModule.ts
@@ -121,13 +129,15 @@ userModule.ts
- dto 目录下必须包含 `dto.ts` 文件
- dto 里的类的属性可以使用小驼峰或者下划线命名
### Good
### Example: Dto 文件命名
#### Good: 使用小写加横线命名
```txt
user-extends.dto.ts
```
### Bad
#### Bad: 使用大驼峰命名
```txt
userDto.ts
@@ -141,7 +151,9 @@ userDto.ts
- 内部只能写使用 syncService 调用的逻辑
- SyncService 只能在 proxy.ts 中使用
### Good
### Example: Proxy 编写
#### Good: Proxy 只使用 SyncService 调用旧业务
```typescript
// user.proxy.ts
@@ -159,7 +171,7 @@ export class UserProxy {
}
```
### Bad
#### Bad: Proxy 中直接查询数据库
```typescript
// user.proxy.ts
@@ -187,7 +199,9 @@ export class UserProxy {
- 文件名使用小写加横线命名(如 `user.model.ts`
- 文件名必须加 `.model.ts` 后缀
### Good
### Example: Model 编写
#### Good: Model 只使用数据库调用
```typescript
// user.model.ts
@@ -206,7 +220,7 @@ export class UserProxy {
}
```
### Bad
#### Bad: Model 中使用 SyncService 调用旧业务
```typescript
// user.model.ts
@@ -229,7 +243,9 @@ export class UserProxy {
- 目前所有的新代码都应该写在 nest 里
### Good
### Example: 业务代码位置
#### Good: 新代码写在 nest 目录下
```typescript
// nest-src/apps/app/src/user/user.controller.ts
@@ -243,7 +259,7 @@ export class UserProxy {
// nest-src/apps/app/src/user/user.module.ts
```
### Bad
#### Bad: 新代码写在旧目录下
```typescript
// proxy/user.js
@@ -256,14 +272,16 @@ export class UserProxy {
- 需要放在指定模块的 constants 文件里
### Good
### Example: 常量定义位置
#### Good: 常量放在对应模块的 constants 文件
```typescript
// user.constants.ts
const MAX_COUNT = 100; // 这是 user 模块需要的
```
### Bad
#### Bad: 常量放在错误模块的 constants 文件
```typescript
// class.constants.ts