@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
|
@@ -3,7 +3,7 @@ import rule from "./graphql-field-definite-assignment";
|
|
|
3
3
|
|
|
4
4
|
tester.run("graphql-field-definite-assignment", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Property with initializer, no ! needed
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
@ObjectType()
|
|
9
9
|
class User {
|
|
@@ -11,7 +11,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
11
11
|
createdAt: Date = new Date();
|
|
12
12
|
}
|
|
13
13
|
`,
|
|
14
|
-
//
|
|
14
|
+
// Property with !, no initializer
|
|
15
15
|
/* typescript */ `
|
|
16
16
|
@ObjectType()
|
|
17
17
|
class User {
|
|
@@ -19,7 +19,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
19
19
|
name!: string;
|
|
20
20
|
}
|
|
21
21
|
`,
|
|
22
|
-
//
|
|
22
|
+
// Optional property, no ! needed
|
|
23
23
|
/* typescript */ `
|
|
24
24
|
@ObjectType()
|
|
25
25
|
class User {
|
|
@@ -27,7 +27,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
27
27
|
age?: number;
|
|
28
28
|
}
|
|
29
29
|
`,
|
|
30
|
-
// InputType
|
|
30
|
+
// InputType class
|
|
31
31
|
/* typescript */ `
|
|
32
32
|
@InputType()
|
|
33
33
|
class CreateUserInput {
|
|
@@ -35,7 +35,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
35
35
|
name!: string;
|
|
36
36
|
}
|
|
37
37
|
`,
|
|
38
|
-
// ArgsType
|
|
38
|
+
// ArgsType class
|
|
39
39
|
/* typescript */ `
|
|
40
40
|
@ArgsType()
|
|
41
41
|
class GetUserArgs {
|
|
@@ -43,14 +43,14 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
43
43
|
id!: string;
|
|
44
44
|
}
|
|
45
45
|
`,
|
|
46
|
-
//
|
|
46
|
+
// Non-GraphQL model class is not checked
|
|
47
47
|
/* typescript */ `
|
|
48
48
|
class NotAGraphQLModel {
|
|
49
49
|
@Field()
|
|
50
50
|
field: string;
|
|
51
51
|
}
|
|
52
52
|
`,
|
|
53
|
-
//
|
|
53
|
+
// Property without @Field decorator is not checked
|
|
54
54
|
/* typescript */ `
|
|
55
55
|
@ObjectType()
|
|
56
56
|
class User {
|
|
@@ -59,7 +59,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
59
59
|
`,
|
|
60
60
|
],
|
|
61
61
|
invalid: [
|
|
62
|
-
//
|
|
62
|
+
// No initializer and no !
|
|
63
63
|
{
|
|
64
64
|
code: /* typescript */ `
|
|
65
65
|
@ObjectType()
|
|
@@ -77,7 +77,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
77
77
|
`,
|
|
78
78
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
79
79
|
},
|
|
80
|
-
//
|
|
80
|
+
// Has initializer but also has !
|
|
81
81
|
{
|
|
82
82
|
code: /* typescript */ `
|
|
83
83
|
@ObjectType()
|
|
@@ -95,7 +95,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
95
95
|
`,
|
|
96
96
|
errors: [{ messageId: "removeDefiniteAssignment" }],
|
|
97
97
|
},
|
|
98
|
-
// InputType -
|
|
98
|
+
// InputType - no initializer and no !
|
|
99
99
|
{
|
|
100
100
|
code: /* typescript */ `
|
|
101
101
|
@InputType()
|
|
@@ -113,7 +113,7 @@ tester.run("graphql-field-definite-assignment", rule, {
|
|
|
113
113
|
`,
|
|
114
114
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
115
115
|
},
|
|
116
|
-
//
|
|
116
|
+
// Number type, no initializer and no !
|
|
117
117
|
{
|
|
118
118
|
code: /* typescript */ `
|
|
119
119
|
@ObjectType()
|
|
@@ -15,15 +15,15 @@ export default createRule<
|
|
|
15
15
|
type: "problem",
|
|
16
16
|
docs: {
|
|
17
17
|
description:
|
|
18
|
-
"
|
|
18
|
+
"Ensures that properties with the GraphQL @Field decorator correctly use the definite assignment assertion (!). Properties without initializers should have !, and properties with initializers should not have !.",
|
|
19
19
|
},
|
|
20
20
|
fixable: "code",
|
|
21
21
|
schema: [],
|
|
22
22
|
messages: {
|
|
23
23
|
addDefiniteAssignment:
|
|
24
|
-
"
|
|
24
|
+
"Property '{{propertyName}}' has a @Field decorator but no initializer, it should have a definite assignment assertion (!).",
|
|
25
25
|
removeDefiniteAssignment:
|
|
26
|
-
"
|
|
26
|
+
"Property '{{propertyName}}' has a @Field decorator and an initializer, the definite assignment assertion (!) should be removed.",
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
defaultOptions: [],
|
|
@@ -56,10 +56,10 @@ export default createRule<
|
|
|
56
56
|
const isOptionalProperty = (
|
|
57
57
|
member: TSESTree.PropertyDefinition,
|
|
58
58
|
): boolean => {
|
|
59
|
-
//
|
|
59
|
+
// Check the AST node's optional flag
|
|
60
60
|
if (member.optional) return true;
|
|
61
61
|
|
|
62
|
-
//
|
|
62
|
+
// Check if there is a ? symbol in the source code (between property name and colon)
|
|
63
63
|
const keyEnd = member.key.range[1];
|
|
64
64
|
const text = source.text;
|
|
65
65
|
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
@@ -81,13 +81,13 @@ export default createRule<
|
|
|
81
81
|
const propertyName = getPropertyName(member);
|
|
82
82
|
if (!propertyName) return;
|
|
83
83
|
|
|
84
|
-
//
|
|
84
|
+
// Optional properties (?:) do not need a definite assignment assertion
|
|
85
85
|
if (isOptionalProperty(member)) return;
|
|
86
86
|
|
|
87
87
|
const hasInit = hasInitializer(member);
|
|
88
88
|
const hasDefinite = hasDefiniteAssignment(member);
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// Case 1: No initializer and no definite assignment assertion
|
|
91
91
|
if (!hasInit && !hasDefinite) {
|
|
92
92
|
context.report({
|
|
93
93
|
node: member,
|
|
@@ -96,15 +96,15 @@ export default createRule<
|
|
|
96
96
|
propertyName,
|
|
97
97
|
},
|
|
98
98
|
fix: (fixer) => {
|
|
99
|
-
//
|
|
99
|
+
// Find the end position of the property name
|
|
100
100
|
const keyEnd = member.key.range[1];
|
|
101
|
-
//
|
|
101
|
+
// Insert ! after the property name
|
|
102
102
|
return fixer.insertTextAfterRange([keyEnd, keyEnd], "!");
|
|
103
103
|
},
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
//
|
|
107
|
+
// Case 2: Has initializer but also has definite assignment assertion
|
|
108
108
|
if (hasInit && hasDefinite) {
|
|
109
109
|
context.report({
|
|
110
110
|
node: member,
|
|
@@ -113,18 +113,18 @@ export default createRule<
|
|
|
113
113
|
propertyName,
|
|
114
114
|
},
|
|
115
115
|
fix: (fixer) => {
|
|
116
|
-
//
|
|
116
|
+
// Find and remove the ! position
|
|
117
117
|
const keyEnd = member.key.range[1];
|
|
118
118
|
const text = source.text;
|
|
119
119
|
|
|
120
|
-
//
|
|
120
|
+
// Find the ! position (between the property name and the colon)
|
|
121
121
|
let exclamationPos = -1;
|
|
122
122
|
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
123
123
|
if (text[i] === "!") {
|
|
124
124
|
exclamationPos = i;
|
|
125
125
|
break;
|
|
126
126
|
}
|
|
127
|
-
//
|
|
127
|
+
// If we encounter a colon, there is no !
|
|
128
128
|
if (text[i] === ":") {
|
|
129
129
|
break;
|
|
130
130
|
}
|
|
@@ -3,29 +3,29 @@ import rule from "./import-bullmq";
|
|
|
3
3
|
|
|
4
4
|
tester.run("import-bullmq", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Correct import source
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
import { BullModule } from "@nest-boot/bullmq";
|
|
9
9
|
`,
|
|
10
|
-
//
|
|
10
|
+
// Importing from another package
|
|
11
11
|
/* typescript */ `
|
|
12
12
|
import { Module } from "@nestjs/common";
|
|
13
13
|
`,
|
|
14
|
-
//
|
|
14
|
+
// Named import
|
|
15
15
|
/* typescript */ `
|
|
16
16
|
import { InjectQueue, Processor } from "@nest-boot/bullmq";
|
|
17
17
|
`,
|
|
18
|
-
//
|
|
18
|
+
// Default import
|
|
19
19
|
/* typescript */ `
|
|
20
20
|
import BullMQ from "@nest-boot/bullmq";
|
|
21
21
|
`,
|
|
22
|
-
//
|
|
22
|
+
// Importing from bullmq core package (should not be replaced)
|
|
23
23
|
/* typescript */ `
|
|
24
24
|
import { Queue, Worker } from "bullmq";
|
|
25
25
|
`,
|
|
26
26
|
],
|
|
27
27
|
invalid: [
|
|
28
|
-
//
|
|
28
|
+
// Importing from @nestjs/bullmq, should be replaced with @nest-boot/bullmq
|
|
29
29
|
{
|
|
30
30
|
code: /* typescript */ `
|
|
31
31
|
import { BullModule } from "@nestjs/bullmq";
|
|
@@ -35,7 +35,7 @@ tester.run("import-bullmq", rule, {
|
|
|
35
35
|
`,
|
|
36
36
|
errors: [{ messageId: "replaceBullmqImport" }],
|
|
37
37
|
},
|
|
38
|
-
// Processor
|
|
38
|
+
// Processor related imports
|
|
39
39
|
{
|
|
40
40
|
code: /* typescript */ `
|
|
41
41
|
import { Processor, InjectQueue } from "@nestjs/bullmq";
|
|
@@ -45,7 +45,7 @@ tester.run("import-bullmq", rule, {
|
|
|
45
45
|
`,
|
|
46
46
|
errors: [{ messageId: "replaceBullmqImport" }],
|
|
47
47
|
},
|
|
48
|
-
//
|
|
48
|
+
// Type import
|
|
49
49
|
{
|
|
50
50
|
code: /* typescript */ `
|
|
51
51
|
import type { BullModuleOptions } from "@nestjs/bullmq";
|
|
@@ -55,7 +55,7 @@ tester.run("import-bullmq", rule, {
|
|
|
55
55
|
`,
|
|
56
56
|
errors: [{ messageId: "replaceBullmqImport" }],
|
|
57
57
|
},
|
|
58
|
-
//
|
|
58
|
+
// Decorator imports
|
|
59
59
|
{
|
|
60
60
|
code: /* typescript */ `
|
|
61
61
|
import { OnQueueActive, OnQueueCompleted } from "@nestjs/bullmq";
|
|
@@ -6,25 +6,26 @@ export default createRule({
|
|
|
6
6
|
type: "problem",
|
|
7
7
|
docs: {
|
|
8
8
|
description:
|
|
9
|
-
"
|
|
9
|
+
"Fix imports from @nestjs/bullmq to use @nest-boot/bullmq instead",
|
|
10
10
|
},
|
|
11
11
|
fixable: "code",
|
|
12
12
|
schema: [],
|
|
13
13
|
messages: {
|
|
14
|
-
replaceBullmqImport:
|
|
14
|
+
replaceBullmqImport:
|
|
15
|
+
"Should import from @nest-boot/bullmq instead of @nestjs/bullmq",
|
|
15
16
|
},
|
|
16
17
|
},
|
|
17
18
|
defaultOptions: [],
|
|
18
19
|
create(context) {
|
|
19
20
|
return {
|
|
20
21
|
ImportDeclaration(node) {
|
|
21
|
-
//
|
|
22
|
+
// Check if importing from @nestjs/bullmq
|
|
22
23
|
if (node.source.value === "@nestjs/bullmq") {
|
|
23
24
|
context.report({
|
|
24
25
|
node,
|
|
25
26
|
messageId: "replaceBullmqImport",
|
|
26
27
|
fix(fixer) {
|
|
27
|
-
//
|
|
28
|
+
// Replace import source with @nest-boot/bullmq
|
|
28
29
|
return fixer.replaceText(node.source, '"@nest-boot/bullmq"');
|
|
29
30
|
},
|
|
30
31
|
});
|
|
@@ -3,25 +3,25 @@ import rule from "./import-graphql";
|
|
|
3
3
|
|
|
4
4
|
tester.run("import-graphql", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Correct import source
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
import { Field, ObjectType } from "@nest-boot/graphql";
|
|
9
9
|
`,
|
|
10
|
-
//
|
|
10
|
+
// Importing from another package
|
|
11
11
|
/* typescript */ `
|
|
12
12
|
import { Module } from "@nestjs/common";
|
|
13
13
|
`,
|
|
14
|
-
//
|
|
14
|
+
// Named import
|
|
15
15
|
/* typescript */ `
|
|
16
16
|
import { Resolver, Query } from "@nest-boot/graphql";
|
|
17
17
|
`,
|
|
18
|
-
//
|
|
18
|
+
// Default import
|
|
19
19
|
/* typescript */ `
|
|
20
20
|
import GraphQL from "@nest-boot/graphql";
|
|
21
21
|
`,
|
|
22
22
|
],
|
|
23
23
|
invalid: [
|
|
24
|
-
//
|
|
24
|
+
// Importing from @nestjs/graphql, should be replaced with @nest-boot/graphql
|
|
25
25
|
{
|
|
26
26
|
code: /* typescript */ `
|
|
27
27
|
import { Field, ObjectType } from "@nestjs/graphql";
|
|
@@ -31,7 +31,7 @@ tester.run("import-graphql", rule, {
|
|
|
31
31
|
`,
|
|
32
32
|
errors: [{ messageId: "replaceGraphqlImport" }],
|
|
33
33
|
},
|
|
34
|
-
// Resolver
|
|
34
|
+
// Resolver related imports
|
|
35
35
|
{
|
|
36
36
|
code: /* typescript */ `
|
|
37
37
|
import { Resolver, Query, Mutation } from "@nestjs/graphql";
|
|
@@ -41,7 +41,7 @@ tester.run("import-graphql", rule, {
|
|
|
41
41
|
`,
|
|
42
42
|
errors: [{ messageId: "replaceGraphqlImport" }],
|
|
43
43
|
},
|
|
44
|
-
//
|
|
44
|
+
// Type import
|
|
45
45
|
{
|
|
46
46
|
code: /* typescript */ `
|
|
47
47
|
import type { GraphQLModule } from "@nestjs/graphql";
|
|
@@ -51,7 +51,7 @@ tester.run("import-graphql", rule, {
|
|
|
51
51
|
`,
|
|
52
52
|
errors: [{ messageId: "replaceGraphqlImport" }],
|
|
53
53
|
},
|
|
54
|
-
//
|
|
54
|
+
// Mixed imports
|
|
55
55
|
{
|
|
56
56
|
code: /* typescript */ `
|
|
57
57
|
import { Args, Int } from "@nestjs/graphql";
|
|
@@ -6,26 +6,26 @@ export default createRule({
|
|
|
6
6
|
type: "problem",
|
|
7
7
|
docs: {
|
|
8
8
|
description:
|
|
9
|
-
"
|
|
9
|
+
"Fix imports from @nestjs/graphql to use @nest-boot/graphql instead",
|
|
10
10
|
},
|
|
11
11
|
fixable: "code",
|
|
12
12
|
schema: [],
|
|
13
13
|
messages: {
|
|
14
14
|
replaceGraphqlImport:
|
|
15
|
-
"
|
|
15
|
+
"Should import from @nest-boot/graphql instead of @nestjs/graphql",
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
defaultOptions: [],
|
|
19
19
|
create(context) {
|
|
20
20
|
return {
|
|
21
21
|
ImportDeclaration(node) {
|
|
22
|
-
//
|
|
22
|
+
// Check if importing from @nestjs/graphql
|
|
23
23
|
if (node.source.value === "@nestjs/graphql") {
|
|
24
24
|
context.report({
|
|
25
25
|
node,
|
|
26
26
|
messageId: "replaceGraphqlImport",
|
|
27
27
|
fix(fixer) {
|
|
28
|
-
//
|
|
28
|
+
// Replace import source with @nest-boot/graphql
|
|
29
29
|
return fixer.replaceText(node.source, '"@nest-boot/graphql"');
|
|
30
30
|
},
|
|
31
31
|
});
|
|
@@ -3,25 +3,25 @@ import rule from "./import-mikro-orm";
|
|
|
3
3
|
|
|
4
4
|
tester.run("import-mikro-orm", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Correct import source
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
import { MikroOrmModule } from "@nest-boot/mikro-orm";
|
|
9
9
|
`,
|
|
10
|
-
//
|
|
10
|
+
// Importing from another package
|
|
11
11
|
/* typescript */ `
|
|
12
12
|
import { Module } from "@nestjs/common";
|
|
13
13
|
`,
|
|
14
|
-
//
|
|
14
|
+
// Importing from @mikro-orm/core (should not be replaced)
|
|
15
15
|
/* typescript */ `
|
|
16
16
|
import { Entity, Property } from "@mikro-orm/core";
|
|
17
17
|
`,
|
|
18
|
-
//
|
|
18
|
+
// Named import
|
|
19
19
|
/* typescript */ `
|
|
20
20
|
import { InjectRepository } from "@nest-boot/mikro-orm";
|
|
21
21
|
`,
|
|
22
22
|
],
|
|
23
23
|
invalid: [
|
|
24
|
-
//
|
|
24
|
+
// Importing from @mikro-orm/nestjs, should be replaced with @nest-boot/mikro-orm
|
|
25
25
|
{
|
|
26
26
|
code: /* typescript */ `
|
|
27
27
|
import { MikroOrmModule } from "@mikro-orm/nestjs";
|
|
@@ -31,7 +31,7 @@ tester.run("import-mikro-orm", rule, {
|
|
|
31
31
|
`,
|
|
32
32
|
errors: [{ messageId: "replaceMikroOrmImport" }],
|
|
33
33
|
},
|
|
34
|
-
// InjectRepository
|
|
34
|
+
// InjectRepository import
|
|
35
35
|
{
|
|
36
36
|
code: /* typescript */ `
|
|
37
37
|
import { InjectRepository } from "@mikro-orm/nestjs";
|
|
@@ -41,7 +41,7 @@ tester.run("import-mikro-orm", rule, {
|
|
|
41
41
|
`,
|
|
42
42
|
errors: [{ messageId: "replaceMikroOrmImport" }],
|
|
43
43
|
},
|
|
44
|
-
//
|
|
44
|
+
// Type import
|
|
45
45
|
{
|
|
46
46
|
code: /* typescript */ `
|
|
47
47
|
import type { MikroOrmModuleOptions } from "@mikro-orm/nestjs";
|
|
@@ -51,7 +51,7 @@ tester.run("import-mikro-orm", rule, {
|
|
|
51
51
|
`,
|
|
52
52
|
errors: [{ messageId: "replaceMikroOrmImport" }],
|
|
53
53
|
},
|
|
54
|
-
//
|
|
54
|
+
// Mixed imports
|
|
55
55
|
{
|
|
56
56
|
code: /* typescript */ `
|
|
57
57
|
import { MikroOrmModule, InjectRepository } from "@mikro-orm/nestjs";
|
|
@@ -6,26 +6,26 @@ export default createRule({
|
|
|
6
6
|
type: "problem",
|
|
7
7
|
docs: {
|
|
8
8
|
description:
|
|
9
|
-
"
|
|
9
|
+
"Fix imports from @mikro-orm/nestjs to use @nest-boot/mikro-orm instead",
|
|
10
10
|
},
|
|
11
11
|
fixable: "code",
|
|
12
12
|
schema: [],
|
|
13
13
|
messages: {
|
|
14
14
|
replaceMikroOrmImport:
|
|
15
|
-
"
|
|
15
|
+
"Should import from @nest-boot/mikro-orm instead of @mikro-orm/nestjs",
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
defaultOptions: [],
|
|
19
19
|
create(context) {
|
|
20
20
|
return {
|
|
21
21
|
ImportDeclaration(node) {
|
|
22
|
-
//
|
|
22
|
+
// Check if importing from @mikro-orm/nestjs
|
|
23
23
|
if (node.source.value === "@mikro-orm/nestjs") {
|
|
24
24
|
context.report({
|
|
25
25
|
node,
|
|
26
26
|
messageId: "replaceMikroOrmImport",
|
|
27
27
|
fix(fixer) {
|
|
28
|
-
//
|
|
28
|
+
// Replace import source with @nest-boot/mikro-orm
|
|
29
29
|
return fixer.replaceText(node.source, '"@nest-boot/mikro-orm"');
|
|
30
30
|
},
|
|
31
31
|
});
|
|
@@ -3,7 +3,7 @@ import rule from "./entity-field-definite-assignment";
|
|
|
3
3
|
|
|
4
4
|
tester.run("entity-field-definite-assignment", rule, {
|
|
5
5
|
valid: [
|
|
6
|
-
//
|
|
6
|
+
// Property with initializer, no ! needed
|
|
7
7
|
/* typescript */ `
|
|
8
8
|
@Entity()
|
|
9
9
|
class User {
|
|
@@ -11,7 +11,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
11
11
|
createdAt: Date = new Date();
|
|
12
12
|
}
|
|
13
13
|
`,
|
|
14
|
-
//
|
|
14
|
+
// Property with !, no initializer
|
|
15
15
|
/* typescript */ `
|
|
16
16
|
@Entity()
|
|
17
17
|
class User {
|
|
@@ -19,7 +19,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
19
19
|
name!: string;
|
|
20
20
|
}
|
|
21
21
|
`,
|
|
22
|
-
//
|
|
22
|
+
// Optional property, no ! needed
|
|
23
23
|
/* typescript */ `
|
|
24
24
|
@Entity()
|
|
25
25
|
class User {
|
|
@@ -27,7 +27,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
27
27
|
age?: number;
|
|
28
28
|
}
|
|
29
29
|
`,
|
|
30
|
-
//
|
|
30
|
+
// Nullable property with initializer
|
|
31
31
|
/* typescript */ `
|
|
32
32
|
@Entity()
|
|
33
33
|
class User {
|
|
@@ -35,21 +35,21 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
35
35
|
name: string | null = null;
|
|
36
36
|
}
|
|
37
37
|
`,
|
|
38
|
-
//
|
|
38
|
+
// Non-Entity class is not checked
|
|
39
39
|
/* typescript */ `
|
|
40
40
|
class NotAnEntity {
|
|
41
41
|
@Property()
|
|
42
42
|
field: string;
|
|
43
43
|
}
|
|
44
44
|
`,
|
|
45
|
-
//
|
|
45
|
+
// Property without @Property decorator is not checked
|
|
46
46
|
/* typescript */ `
|
|
47
47
|
@Entity()
|
|
48
48
|
class User {
|
|
49
49
|
field: string;
|
|
50
50
|
}
|
|
51
51
|
`,
|
|
52
|
-
// @Enum
|
|
52
|
+
// @Enum decorator - with !
|
|
53
53
|
/* typescript */ `
|
|
54
54
|
@Entity()
|
|
55
55
|
class User {
|
|
@@ -57,7 +57,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
57
57
|
role!: UserRole;
|
|
58
58
|
}
|
|
59
59
|
`,
|
|
60
|
-
// @OneToOne
|
|
60
|
+
// @OneToOne decorator - using Ref
|
|
61
61
|
/* typescript */ `
|
|
62
62
|
@Entity()
|
|
63
63
|
class User {
|
|
@@ -65,7 +65,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
65
65
|
profile!: Ref<Profile>;
|
|
66
66
|
}
|
|
67
67
|
`,
|
|
68
|
-
// @OneToMany
|
|
68
|
+
// @OneToMany decorator - initialized with Collection
|
|
69
69
|
/* typescript */ `
|
|
70
70
|
@Entity()
|
|
71
71
|
class User {
|
|
@@ -73,7 +73,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
73
73
|
posts = new Collection<Post>(this);
|
|
74
74
|
}
|
|
75
75
|
`,
|
|
76
|
-
// @ManyToOne
|
|
76
|
+
// @ManyToOne decorator - using Ref
|
|
77
77
|
/* typescript */ `
|
|
78
78
|
@Entity()
|
|
79
79
|
class Post {
|
|
@@ -81,7 +81,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
81
81
|
author!: Ref<User>;
|
|
82
82
|
}
|
|
83
83
|
`,
|
|
84
|
-
// @ManyToMany
|
|
84
|
+
// @ManyToMany decorator - initialized with Collection
|
|
85
85
|
/* typescript */ `
|
|
86
86
|
@Entity()
|
|
87
87
|
class User {
|
|
@@ -91,7 +91,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
91
91
|
`,
|
|
92
92
|
],
|
|
93
93
|
invalid: [
|
|
94
|
-
//
|
|
94
|
+
// No initializer and no !
|
|
95
95
|
{
|
|
96
96
|
code: /* typescript */ `
|
|
97
97
|
@Entity()
|
|
@@ -109,7 +109,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
109
109
|
`,
|
|
110
110
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
111
111
|
},
|
|
112
|
-
//
|
|
112
|
+
// Has initializer but also has !
|
|
113
113
|
{
|
|
114
114
|
code: /* typescript */ `
|
|
115
115
|
@Entity()
|
|
@@ -127,7 +127,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
127
127
|
`,
|
|
128
128
|
errors: [{ messageId: "removeDefiniteAssignment" }],
|
|
129
129
|
},
|
|
130
|
-
// @Enum
|
|
130
|
+
// @Enum decorator - no initializer and no !
|
|
131
131
|
{
|
|
132
132
|
code: /* typescript */ `
|
|
133
133
|
@Entity()
|
|
@@ -145,7 +145,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
145
145
|
`,
|
|
146
146
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
147
147
|
},
|
|
148
|
-
// @OneToOne
|
|
148
|
+
// @OneToOne decorator - no initializer and no ! (using Ref)
|
|
149
149
|
{
|
|
150
150
|
code: /* typescript */ `
|
|
151
151
|
@Entity()
|
|
@@ -163,7 +163,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
163
163
|
`,
|
|
164
164
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
165
165
|
},
|
|
166
|
-
// @OneToMany
|
|
166
|
+
// @OneToMany decorator - has initializer but also has ! (using Collection)
|
|
167
167
|
{
|
|
168
168
|
code: /* typescript */ `
|
|
169
169
|
@Entity()
|
|
@@ -181,7 +181,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
181
181
|
`,
|
|
182
182
|
errors: [{ messageId: "removeDefiniteAssignment" }],
|
|
183
183
|
},
|
|
184
|
-
// @ManyToOne
|
|
184
|
+
// @ManyToOne decorator - no initializer and no ! (using Ref)
|
|
185
185
|
{
|
|
186
186
|
code: /* typescript */ `
|
|
187
187
|
@Entity()
|
|
@@ -199,7 +199,7 @@ tester.run("entity-field-definite-assignment", rule, {
|
|
|
199
199
|
`,
|
|
200
200
|
errors: [{ messageId: "addDefiniteAssignment" }],
|
|
201
201
|
},
|
|
202
|
-
// @ManyToMany
|
|
202
|
+
// @ManyToMany decorator - has initializer but also has ! (using Collection)
|
|
203
203
|
{
|
|
204
204
|
code: /* typescript */ `
|
|
205
205
|
@Entity()
|