feat: 在 JS/TS 基础规范和 NestJS 规范中添加常量定义位置规则,要求常量放在对应模块的 constants 文件中

This commit is contained in:
Lyda
2026-03-04 10:52:17 +08:00
parent ea4f4d41c8
commit 6a5006077b
2 changed files with 42 additions and 1 deletions
+20
View File
@@ -69,6 +69,26 @@ const maxCount = 100;
const userStatus = "active";
```
## 基于 JsTs.Base.NoMagicStringsAndNumbers 抽离的静态常量需要放在对应文件里 `[JsTs.Base.ConstantsDefinition]`
> - severity `warn`
- 需要放在指定模块的 constants 文件里
### Good
```javascript
// user.constants.js
const MAX_COUNT = 100; // 这是 user 模块需要的
```
### Bad
```javascript
// class.constants.js
const MAX_COUNT = 100; // 这是 user 模块需要的
```
## class 和 interface 命名使用大驼峰命名 `[JsTs.Base.ClassUpperCamel]`
> - severity `warn`
+22 -1
View File
@@ -1,6 +1,6 @@
# Nestjs 项目下的规范 `[JsTs.Nest]`
> - includes `*.controller.ts` `*.service.ts` `*.module.ts` `*.dto.ts` `*.pipe.ts` `*.guard.ts` `*.interceptor.ts` `*.filter.ts` `*.exception-filter.ts` `*.proxy.ts` `*.model.ts`
> - includes `*.controller.ts` `*.service.ts` `*.module.ts` `*.dto.ts` `*.pipe.ts` `*.guard.ts` `*.interceptor.ts` `*.filter.ts` `*.exception-filter.ts` `*.proxy.ts` `*.model.ts` `*.constants.ts`
> - override `[JsTs.FileName]`
## 目录框架规范 `[JsTs.Nest.DirStructure]`
@@ -248,3 +248,24 @@ export class UserProxy {
```typescript
// proxy/user.js
```
## 基于 JsTs.Base.NoMagicStringsAndNumbers 抽离的静态常量需要放在对应文件里 `[JsTs.Nest.ConstantsDefinition]`
> - severity `warn`
> - override `[JsTs.Base.ConstantsDefinition]`
- 需要放在指定模块的 constants 文件里
### Good
```typescript
// user.constants.ts
const MAX_COUNT = 100; // 这是 user 模块需要的
```
### Bad
```typescript
// class.constants.ts
const MAX_COUNT = 100; // 这是 user 模块需要的
```