@nest-boot/eslint-plugin 7.0.4 → 7.0.6
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/rules/graphql/graphql-field-config-from-types.d.ts +3 -1
- package/dist/rules/graphql/graphql-field-config-from-types.js +39 -41
- package/dist/rules/graphql/graphql-field-config-from-types.js.map +1 -1
- package/dist/rules/graphql/graphql-field-definite-assignment.d.ts +3 -1
- package/dist/rules/graphql/graphql-field-definite-assignment.js +13 -13
- package/dist/rules/graphql/graphql-field-definite-assignment.js.map +1 -1
- package/dist/rules/import/import-bullmq.d.ts +3 -1
- package/dist/rules/import/import-bullmq.js +4 -4
- package/dist/rules/import/import-bullmq.js.map +1 -1
- package/dist/rules/import/import-graphql.d.ts +3 -1
- package/dist/rules/import/import-graphql.js +4 -4
- package/dist/rules/import/import-graphql.js.map +1 -1
- package/dist/rules/import/import-mikro-orm.d.ts +3 -1
- package/dist/rules/import/import-mikro-orm.js +4 -4
- package/dist/rules/import/import-mikro-orm.js.map +1 -1
- package/dist/rules/index.d.ts +21 -7
- package/dist/rules/mikro-orm/entity-field-definite-assignment.d.ts +3 -1
- package/dist/rules/mikro-orm/entity-field-definite-assignment.js +10 -10
- package/dist/rules/mikro-orm/entity-field-definite-assignment.js.map +1 -1
- package/dist/rules/mikro-orm/entity-property-config-from-types.d.ts +3 -1
- package/dist/rules/mikro-orm/entity-property-config-from-types.js +106 -106
- package/dist/rules/mikro-orm/entity-property-config-from-types.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/createRule.d.ts +3 -1
- package/dist/utils/decorators.d.ts +16 -16
- package/dist/utils/decorators.js +16 -16
- package/package.json +14 -9
- package/src/rules/graphql/graphql-field-config-from-types.spec.ts +18 -18
- package/src/rules/graphql/graphql-field-config-from-types.ts +40 -44
- package/src/rules/graphql/graphql-field-definite-assignment.spec.ts +11 -11
- package/src/rules/graphql/graphql-field-definite-assignment.ts +13 -13
- package/src/rules/import/import-bullmq.spec.ts +9 -9
- package/src/rules/import/import-bullmq.ts +5 -4
- package/src/rules/import/import-graphql.spec.ts +8 -8
- package/src/rules/import/import-graphql.ts +4 -4
- package/src/rules/import/import-mikro-orm.spec.ts +8 -8
- package/src/rules/import/import-mikro-orm.ts +4 -4
- package/src/rules/mikro-orm/entity-field-definite-assignment.spec.ts +18 -18
- package/src/rules/mikro-orm/entity-field-definite-assignment.ts +10 -10
- package/src/rules/mikro-orm/entity-property-config-from-types.spec.ts +22 -22
- package/src/rules/mikro-orm/entity-property-config-from-types.ts +111 -110
- package/src/utils/decorators.ts +16 -16
- package/tsconfig.json +0 -1
|
@@ -50,10 +50,10 @@ export default createRule({
|
|
|
50
50
|
const isOptionalProperty = (
|
|
51
51
|
member: TSESTree.PropertyDefinition,
|
|
52
52
|
): boolean => {
|
|
53
|
-
//
|
|
53
|
+
// Check the AST node's optional flag
|
|
54
54
|
if (member.optional) return true;
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// Check if there is a ? symbol in the source code (between property name and colon)
|
|
57
57
|
const keyEnd = member.key.range[1];
|
|
58
58
|
const text = source.text;
|
|
59
59
|
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
@@ -87,13 +87,13 @@ export default createRule({
|
|
|
87
87
|
const propertyName = getPropertyName(member);
|
|
88
88
|
if (!propertyName) return;
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// Optional properties (?:) do not need a definite assignment assertion
|
|
91
91
|
if (isOptionalProperty(member)) return;
|
|
92
92
|
|
|
93
93
|
const hasInit = hasInitializer(member);
|
|
94
94
|
const hasDefinite = hasDefiniteAssignment(member);
|
|
95
95
|
|
|
96
|
-
//
|
|
96
|
+
// Case 1: No initializer and no definite assignment assertion
|
|
97
97
|
if (!hasInit && !hasDefinite) {
|
|
98
98
|
context.report({
|
|
99
99
|
node: member,
|
|
@@ -102,15 +102,15 @@ export default createRule({
|
|
|
102
102
|
propertyName,
|
|
103
103
|
},
|
|
104
104
|
fix: (fixer) => {
|
|
105
|
-
//
|
|
105
|
+
// Find the end position of the property name
|
|
106
106
|
const keyEnd = member.key.range[1];
|
|
107
|
-
//
|
|
107
|
+
// Insert ! after the property name
|
|
108
108
|
return fixer.insertTextAfterRange([keyEnd, keyEnd], "!");
|
|
109
109
|
},
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
//
|
|
113
|
+
// Case 2: Has initializer but also has definite assignment assertion
|
|
114
114
|
if (hasInit && hasDefinite) {
|
|
115
115
|
context.report({
|
|
116
116
|
node: member,
|
|
@@ -119,18 +119,18 @@ export default createRule({
|
|
|
119
119
|
propertyName,
|
|
120
120
|
},
|
|
121
121
|
fix: (fixer) => {
|
|
122
|
-
//
|
|
122
|
+
// Find and remove the ! position
|
|
123
123
|
const keyEnd = member.key.range[1];
|
|
124
124
|
const text = source.text;
|
|
125
125
|
|
|
126
|
-
//
|
|
126
|
+
// Find the ! position (between the property name and the colon)
|
|
127
127
|
let exclamationPos = -1;
|
|
128
128
|
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
129
129
|
if (text[i] === "!") {
|
|
130
130
|
exclamationPos = i;
|
|
131
131
|
break;
|
|
132
132
|
}
|
|
133
|
-
//
|
|
133
|
+
// If we encounter a colon, there is no !
|
|
134
134
|
if (text[i] === ":") {
|
|
135
135
|
break;
|
|
136
136
|
}
|
|
@@ -3,7 +3,7 @@ import rule from "./entity-property-config-from-types";
|
|
|
3
3
|
|
|
4
4
|
tester.run("entity-property-config-from-types", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Correct string type
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
import { Entity, Property } from "@mikro-orm/core";
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
13
13
|
name!: string;
|
|
14
14
|
}
|
|
15
15
|
`,
|
|
16
|
-
//
|
|
16
|
+
// Correct nullable configuration
|
|
17
17
|
/* typescript */ `
|
|
18
18
|
import { Entity, Property } from "@mikro-orm/core";
|
|
19
19
|
|
|
@@ -23,7 +23,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
23
23
|
name?: string;
|
|
24
24
|
}
|
|
25
25
|
`,
|
|
26
|
-
//
|
|
26
|
+
// Using Opt<T> type with initializer
|
|
27
27
|
/* typescript */ `
|
|
28
28
|
import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
33
33
|
isActive: Opt<boolean> = false;
|
|
34
34
|
}
|
|
35
35
|
`,
|
|
36
|
-
//
|
|
36
|
+
// Relation decorators don't need @Property
|
|
37
37
|
/* typescript */ `
|
|
38
38
|
import { Entity, ManyToOne } from "@mikro-orm/core";
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
43
43
|
author!: User;
|
|
44
44
|
}
|
|
45
45
|
`,
|
|
46
|
-
// PrimaryKey
|
|
46
|
+
// PrimaryKey needs type configuration
|
|
47
47
|
/* typescript */ `
|
|
48
48
|
import { Entity, PrimaryKey, t } from "@mikro-orm/core";
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
53
53
|
id!: number;
|
|
54
54
|
}
|
|
55
55
|
`,
|
|
56
|
-
//
|
|
56
|
+
// Enum type uses @Enum
|
|
57
57
|
/* typescript */ `
|
|
58
58
|
import { Entity, Enum } from "@mikro-orm/core";
|
|
59
59
|
|
|
@@ -68,7 +68,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
68
68
|
role!: Role;
|
|
69
69
|
}
|
|
70
70
|
`,
|
|
71
|
-
//
|
|
71
|
+
// Array type
|
|
72
72
|
/* typescript */ `
|
|
73
73
|
import { Entity, Property } from "@mikro-orm/core";
|
|
74
74
|
|
|
@@ -78,7 +78,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
78
78
|
tags!: number[];
|
|
79
79
|
}
|
|
80
80
|
`,
|
|
81
|
-
// boolean
|
|
81
|
+
// boolean type
|
|
82
82
|
/* typescript */ `
|
|
83
83
|
import { Entity, Property } from "@mikro-orm/core";
|
|
84
84
|
|
|
@@ -88,7 +88,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
88
88
|
isActive!: boolean;
|
|
89
89
|
}
|
|
90
90
|
`,
|
|
91
|
-
// Date
|
|
91
|
+
// Date type using t.datetime
|
|
92
92
|
/* typescript */ `
|
|
93
93
|
import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
94
94
|
|
|
@@ -98,7 +98,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
98
98
|
createdAt: Opt<Date> = new Date();
|
|
99
99
|
}
|
|
100
100
|
`,
|
|
101
|
-
// Date
|
|
101
|
+
// Date type using t.date (valid Date type configuration)
|
|
102
102
|
/* typescript */ `
|
|
103
103
|
import { Entity, Property } from "@mikro-orm/core";
|
|
104
104
|
|
|
@@ -108,7 +108,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
108
108
|
birthDate!: Date;
|
|
109
109
|
}
|
|
110
110
|
`,
|
|
111
|
-
// Date
|
|
111
|
+
// Date type using t.time (valid Date type configuration)
|
|
112
112
|
/* typescript */ `
|
|
113
113
|
import { Entity, Property } from "@mikro-orm/core";
|
|
114
114
|
|
|
@@ -118,7 +118,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
118
118
|
workTime!: Date;
|
|
119
119
|
}
|
|
120
120
|
`,
|
|
121
|
-
//
|
|
121
|
+
// Using t.text instead of t.string (valid string type configuration)
|
|
122
122
|
/* typescript */ `
|
|
123
123
|
import { Entity, Property } from "@mikro-orm/core";
|
|
124
124
|
|
|
@@ -128,7 +128,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
128
128
|
description!: string;
|
|
129
129
|
}
|
|
130
130
|
`,
|
|
131
|
-
//
|
|
131
|
+
// Non-Entity class is not checked
|
|
132
132
|
/* typescript */ `
|
|
133
133
|
class NotAnEntity {
|
|
134
134
|
field: string;
|
|
@@ -136,7 +136,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
136
136
|
`,
|
|
137
137
|
],
|
|
138
138
|
invalid: [
|
|
139
|
-
// type
|
|
139
|
+
// type configuration mismatch
|
|
140
140
|
{
|
|
141
141
|
code: /* typescript */ `
|
|
142
142
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -158,7 +158,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
158
158
|
`,
|
|
159
159
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
160
160
|
},
|
|
161
|
-
// nullable
|
|
161
|
+
// nullable configuration mismatch
|
|
162
162
|
{
|
|
163
163
|
code: /* typescript */ `
|
|
164
164
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -180,7 +180,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
180
180
|
`,
|
|
181
181
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
182
182
|
},
|
|
183
|
-
//
|
|
183
|
+
// Has initializer but not using Opt<T>
|
|
184
184
|
{
|
|
185
185
|
code: /* typescript */ `
|
|
186
186
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -202,7 +202,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
202
202
|
`,
|
|
203
203
|
errors: [{ messageId: "useOptTypeForInitializedProperty" }],
|
|
204
204
|
},
|
|
205
|
-
//
|
|
205
|
+
// Enum type should use @Enum decorator
|
|
206
206
|
{
|
|
207
207
|
code: /* typescript */ `
|
|
208
208
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -234,7 +234,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
234
234
|
`,
|
|
235
235
|
errors: [{ messageId: "useEnumDecorator" }],
|
|
236
236
|
},
|
|
237
|
-
// @Enum
|
|
237
|
+
// @Enum nullable configuration mismatch
|
|
238
238
|
{
|
|
239
239
|
code: /* typescript */ `
|
|
240
240
|
import { Entity, Enum } from "@mikro-orm/core";
|
|
@@ -266,7 +266,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
266
266
|
`,
|
|
267
267
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
268
268
|
},
|
|
269
|
-
//
|
|
269
|
+
// Array type configuration mismatch
|
|
270
270
|
{
|
|
271
271
|
code: /* typescript */ `
|
|
272
272
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -288,7 +288,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
288
288
|
`,
|
|
289
289
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
290
290
|
},
|
|
291
|
-
//
|
|
291
|
+
// Empty @Property() should add type: t.boolean
|
|
292
292
|
{
|
|
293
293
|
code: /* typescript */ `
|
|
294
294
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -310,7 +310,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
310
310
|
`,
|
|
311
311
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
312
312
|
},
|
|
313
|
-
//
|
|
313
|
+
// Empty @Property() should add type: t.datetime (Date type)
|
|
314
314
|
{
|
|
315
315
|
code: /* typescript */ `
|
|
316
316
|
import { Entity, Property } from "@mikro-orm/core";
|
|
@@ -332,7 +332,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
332
332
|
`,
|
|
333
333
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
334
334
|
},
|
|
335
|
-
// Date
|
|
335
|
+
// Date type with wrong configuration should be fixed to t.datetime
|
|
336
336
|
{
|
|
337
337
|
code: /* typescript */ `
|
|
338
338
|
import { Entity, Property } from "@mikro-orm/core";
|