@nest-boot/eslint-plugin 7.0.1 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "@nest-boot/eslint-plugin",
3
- "version": "7.0.1",
3
+ "version": "7.0.3",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "exports": "./dist/index.js",
7
7
  "dependencies": {
8
8
  "@typescript-eslint/utils": "^8.44.1"
9
9
  },
10
+ "peerDependencies": {
11
+ "@typescript-eslint/parser": "^8.0.0",
12
+ "eslint": "^9.0.0",
13
+ "typescript": "^5.0.0"
14
+ },
10
15
  "devDependencies": {
11
16
  "@eslint/eslintrc": "^3.3.1",
12
17
  "@eslint/js": "^9.36.0",
13
18
  "@jest/globals": "^30.2.0",
14
- "@nest-boot/tsconfig": "^7.0.0",
15
19
  "@types/node": "^22.18.6",
20
+ "@typescript-eslint/parser": "^8.44.1",
16
21
  "@typescript-eslint/rule-tester": "^8.44.1",
17
22
  "eslint": "^9.36.0",
18
23
  "eslint-config-prettier": "^10.1.8",
@@ -20,7 +25,8 @@
20
25
  "jest": "^29.7.0",
21
26
  "ts-jest": "^29.4.4",
22
27
  "typescript": "^5.9.3",
23
- "typescript-eslint": "^8.46.2"
28
+ "typescript-eslint": "^8.46.2",
29
+ "@nest-boot/tsconfig": "^7.0.1"
24
30
  },
25
31
  "publishConfig": {
26
32
  "access": "public"
@@ -88,6 +88,36 @@ tester.run("entity-property-config-from-types", rule, {
88
88
  isActive!: boolean;
89
89
  }
90
90
  `,
91
+ // Date 类型使用 t.datetime
92
+ /* typescript */ `
93
+ import { Entity, Property, Opt } from "@mikro-orm/core";
94
+
95
+ @Entity()
96
+ class User {
97
+ @Property({ type: t.datetime, defaultRaw: 'now()' })
98
+ createdAt: Opt<Date> = new Date();
99
+ }
100
+ `,
101
+ // Date 类型使用 t.date(有效的 Date 类型配置)
102
+ /* typescript */ `
103
+ import { Entity, Property } from "@mikro-orm/core";
104
+
105
+ @Entity()
106
+ class User {
107
+ @Property({ type: t.date })
108
+ birthDate!: Date;
109
+ }
110
+ `,
111
+ // Date 类型使用 t.time(有效的 Date 类型配置)
112
+ /* typescript */ `
113
+ import { Entity, Property } from "@mikro-orm/core";
114
+
115
+ @Entity()
116
+ class User {
117
+ @Property({ type: t.time })
118
+ workTime!: Date;
119
+ }
120
+ `,
91
121
  // 使用 t.text 代替 t.string(有效的 string 类型配置)
92
122
  /* typescript */ `
93
123
  import { Entity, Property } from "@mikro-orm/core";
@@ -258,5 +288,71 @@ tester.run("entity-property-config-from-types", rule, {
258
288
  `,
259
289
  errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
260
290
  },
291
+ // 空的 @Property() 应该添加 type: t.boolean
292
+ {
293
+ code: /* typescript */ `
294
+ import { Entity, Property } from "@mikro-orm/core";
295
+
296
+ @Entity()
297
+ class User {
298
+ @Property()
299
+ published!: boolean;
300
+ }
301
+ `,
302
+ output: /* typescript */ `
303
+ import { Entity, Property } from "@mikro-orm/core";
304
+
305
+ @Entity()
306
+ class User {
307
+ @Property({ type: t.boolean })
308
+ published!: boolean;
309
+ }
310
+ `,
311
+ errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
312
+ },
313
+ // 空的 @Property() 应该添加 type: t.datetime(Date 类型)
314
+ {
315
+ code: /* typescript */ `
316
+ import { Entity, Property } from "@mikro-orm/core";
317
+
318
+ @Entity()
319
+ class User {
320
+ @Property()
321
+ createdAt!: Date;
322
+ }
323
+ `,
324
+ output: /* typescript */ `
325
+ import { Entity, Property } from "@mikro-orm/core";
326
+
327
+ @Entity()
328
+ class User {
329
+ @Property({ type: t.datetime })
330
+ createdAt!: Date;
331
+ }
332
+ `,
333
+ errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
334
+ },
335
+ // Date 类型配置错误应该修正为 t.datetime
336
+ {
337
+ code: /* typescript */ `
338
+ import { Entity, Property } from "@mikro-orm/core";
339
+
340
+ @Entity()
341
+ class User {
342
+ @Property({ type: t.string })
343
+ createdAt!: Date;
344
+ }
345
+ `,
346
+ output: /* typescript */ `
347
+ import { Entity, Property } from "@mikro-orm/core";
348
+
349
+ @Entity()
350
+ class User {
351
+ @Property({ type: t.datetime })
352
+ createdAt!: Date;
353
+ }
354
+ `,
355
+ errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
356
+ },
261
357
  ],
262
358
  });
@@ -100,7 +100,7 @@ export default createRule<
100
100
  case "boolean":
101
101
  return "t.boolean"; // 默认使用 t.boolean
102
102
  case "Date":
103
- return null; // Date 类型不需要指定
103
+ return "t.datetime"; // 默认使用 t.datetime
104
104
  case "GraphQLJSONObject":
105
105
  case "Record":
106
106
  return "t.json";
@@ -206,6 +206,21 @@ export default createRule<
206
206
  return false;
207
207
  };
208
208
 
209
+ const isValidDateType = (typeConfig: string | null): boolean => {
210
+ if (!typeConfig) return false;
211
+
212
+ // 接受 t.datetime, t.date, t.time
213
+ if (
214
+ typeConfig === "t.datetime" ||
215
+ typeConfig === "t.date" ||
216
+ typeConfig === "t.time"
217
+ ) {
218
+ return true;
219
+ }
220
+
221
+ return false;
222
+ };
223
+
209
224
  const getIdentifierName = (node: TSESTree.TypeNode): string | null => {
210
225
  if (
211
226
  node.type === AST_NODE_TYPES.TSTypeReference &&
@@ -624,6 +639,12 @@ export default createRule<
624
639
  ) {
625
640
  // 保留有效的 number 类型配置
626
641
  finalInfo.propertyType = currentConfig.type;
642
+ } else if (
643
+ info.propertyType === "t.datetime" &&
644
+ isValidDateType(currentConfig.type)
645
+ ) {
646
+ // 保留有效的 Date 类型配置
647
+ finalInfo.propertyType = currentConfig.type;
627
648
  } else if (
628
649
  info.isArray &&
629
650
  info.arrayElementTypeName === "number" &&
@@ -1063,6 +1084,11 @@ export default createRule<
1063
1084
  isValidNumberType(currentConfig.type)
1064
1085
  ) {
1065
1086
  // 当前配置是有效的 number 类型配置,不需要修改
1087
+ } else if (
1088
+ expectedType === "t.datetime" &&
1089
+ isValidDateType(currentConfig.type)
1090
+ ) {
1091
+ // 当前配置是有效的 Date 类型配置,不需要修改
1066
1092
  } else if (
1067
1093
  expectedType === "t.array" &&
1068
1094
  typeInfo.arrayElementTypeName === "number" &&