@nest-boot/eslint-plugin 7.0.0-beta.3 → 7.0.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-boot/eslint-plugin",
3
- "version": "7.0.0-beta.3",
3
+ "version": "7.0.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "exports": "./dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "@eslint/eslintrc": "^3.3.1",
12
12
  "@eslint/js": "^9.36.0",
13
13
  "@jest/globals": "^30.2.0",
14
- "@nest-boot/tsconfig": "^7.0.0-beta.1",
14
+ "@nest-boot/tsconfig": "^7.0.0",
15
15
  "@types/node": "^22.18.6",
16
16
  "@typescript-eslint/rule-tester": "^8.44.1",
17
17
  "eslint": "^9.36.0",
@@ -49,6 +49,46 @@ tester.run("entity-field-definite-assignment", rule, {
49
49
  field: string;
50
50
  }
51
51
  `,
52
+ // @Enum 装饰器 - 有 !
53
+ /* typescript */ `
54
+ @Entity()
55
+ class User {
56
+ @Enum()
57
+ role!: UserRole;
58
+ }
59
+ `,
60
+ // @OneToOne 装饰器 - 使用 Ref
61
+ /* typescript */ `
62
+ @Entity()
63
+ class User {
64
+ @OneToOne()
65
+ profile!: Ref<Profile>;
66
+ }
67
+ `,
68
+ // @OneToMany 装饰器 - 使用 Collection 初始化
69
+ /* typescript */ `
70
+ @Entity()
71
+ class User {
72
+ @OneToMany()
73
+ posts = new Collection<Post>(this);
74
+ }
75
+ `,
76
+ // @ManyToOne 装饰器 - 使用 Ref
77
+ /* typescript */ `
78
+ @Entity()
79
+ class Post {
80
+ @ManyToOne()
81
+ author!: Ref<User>;
82
+ }
83
+ `,
84
+ // @ManyToMany 装饰器 - 使用 Collection 初始化
85
+ /* typescript */ `
86
+ @Entity()
87
+ class User {
88
+ @ManyToMany()
89
+ tags = new Collection<Tag>(this);
90
+ }
91
+ `,
52
92
  ],
53
93
  invalid: [
54
94
  // 没有初始化值,也没有 !
@@ -87,5 +127,95 @@ tester.run("entity-field-definite-assignment", rule, {
87
127
  `,
88
128
  errors: [{ messageId: "removeDefiniteAssignment" }],
89
129
  },
130
+ // @Enum 装饰器 - 没有初始化值,也没有 !
131
+ {
132
+ code: /* typescript */ `
133
+ @Entity()
134
+ class User {
135
+ @Enum()
136
+ role: UserRole;
137
+ }
138
+ `,
139
+ output: /* typescript */ `
140
+ @Entity()
141
+ class User {
142
+ @Enum()
143
+ role!: UserRole;
144
+ }
145
+ `,
146
+ errors: [{ messageId: "addDefiniteAssignment" }],
147
+ },
148
+ // @OneToOne 装饰器 - 没有初始化值,也没有 ! (使用 Ref)
149
+ {
150
+ code: /* typescript */ `
151
+ @Entity()
152
+ class User {
153
+ @OneToOne()
154
+ profile: Ref<Profile>;
155
+ }
156
+ `,
157
+ output: /* typescript */ `
158
+ @Entity()
159
+ class User {
160
+ @OneToOne()
161
+ profile!: Ref<Profile>;
162
+ }
163
+ `,
164
+ errors: [{ messageId: "addDefiniteAssignment" }],
165
+ },
166
+ // @OneToMany 装饰器 - 有初始化值,但也有 ! (使用 Collection)
167
+ {
168
+ code: /* typescript */ `
169
+ @Entity()
170
+ class User {
171
+ @OneToMany()
172
+ posts!: Collection<Post> = new Collection<Post>(this);
173
+ }
174
+ `,
175
+ output: /* typescript */ `
176
+ @Entity()
177
+ class User {
178
+ @OneToMany()
179
+ posts: Collection<Post> = new Collection<Post>(this);
180
+ }
181
+ `,
182
+ errors: [{ messageId: "removeDefiniteAssignment" }],
183
+ },
184
+ // @ManyToOne 装饰器 - 没有初始化值,也没有 ! (使用 Ref)
185
+ {
186
+ code: /* typescript */ `
187
+ @Entity()
188
+ class Post {
189
+ @ManyToOne()
190
+ author: Ref<User>;
191
+ }
192
+ `,
193
+ output: /* typescript */ `
194
+ @Entity()
195
+ class Post {
196
+ @ManyToOne()
197
+ author!: Ref<User>;
198
+ }
199
+ `,
200
+ errors: [{ messageId: "addDefiniteAssignment" }],
201
+ },
202
+ // @ManyToMany 装饰器 - 有初始化值,但也有 ! (使用 Collection)
203
+ {
204
+ code: /* typescript */ `
205
+ @Entity()
206
+ class User {
207
+ @ManyToMany()
208
+ tags!: Collection<Tag> = new Collection<Tag>(this);
209
+ }
210
+ `,
211
+ output: /* typescript */ `
212
+ @Entity()
213
+ class User {
214
+ @ManyToMany()
215
+ tags: Collection<Tag> = new Collection<Tag>(this);
216
+ }
217
+ `,
218
+ errors: [{ messageId: "removeDefiniteAssignment" }],
219
+ },
90
220
  ],
91
221
  });
@@ -70,7 +70,17 @@ export default createRule({
70
70
 
71
71
  node.body.body.forEach((member: TSESTree.ClassElement) => {
72
72
  if (member.type !== AST_NODE_TYPES.PropertyDefinition) return;
73
- if (!hasPropertyDecorator(member, "Property")) return;
73
+ if (
74
+ !hasPropertyDecorator(member, [
75
+ "Property",
76
+ "Enum",
77
+ "OneToOne",
78
+ "OneToMany",
79
+ "ManyToOne",
80
+ "ManyToMany",
81
+ ])
82
+ )
83
+ return;
74
84
 
75
85
  const propertyName = getPropertyName(member);
76
86
  if (!propertyName) return;