@nest-boot/eslint-plugin 7.0.0-beta.1 → 7.0.0-beta.2
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 +2 -2
- package/CHANGELOG.md +2 -20
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/dist/rules/graphql/graphql-field-config-from-types.d.ts +6 -0
- package/dist/rules/graphql/graphql-field-config-from-types.js +417 -0
- package/dist/rules/graphql/graphql-field-config-from-types.js.map +1 -0
- package/dist/rules/graphql/graphql-field-definite-assignment.d.ts +2 -0
- package/dist/rules/graphql/graphql-field-definite-assignment.js +125 -0
- package/dist/rules/graphql/graphql-field-definite-assignment.js.map +1 -0
- package/dist/rules/import/import-bullmq.d.ts +2 -0
- package/dist/rules/import/import-bullmq.js +36 -0
- package/dist/rules/import/import-bullmq.js.map +1 -0
- package/dist/rules/import/import-graphql.d.ts +2 -0
- package/dist/rules/import/import-graphql.js +36 -0
- package/dist/rules/import/import-graphql.js.map +1 -0
- package/dist/rules/import/import-mikro-orm.d.ts +2 -0
- package/dist/rules/import/import-mikro-orm.js +36 -0
- package/dist/rules/import/import-mikro-orm.js.map +1 -0
- package/dist/rules/index.d.ts +9 -0
- package/dist/rules/index.js +16 -11
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/mikro-orm/entity-field-definite-assignment.d.ts +2 -0
- package/dist/rules/mikro-orm/entity-field-definite-assignment.js +125 -0
- package/dist/rules/mikro-orm/entity-field-definite-assignment.js.map +1 -0
- package/dist/rules/mikro-orm/entity-property-config-from-types.d.ts +3 -0
- package/dist/rules/mikro-orm/entity-property-config-from-types.js +881 -0
- package/dist/rules/mikro-orm/entity-property-config-from-types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils/createRule.d.ts +2 -0
- package/dist/utils/createRule.js +1 -1
- package/dist/utils/createRule.js.map +1 -1
- package/dist/utils/decorators.d.ts +29 -0
- package/dist/utils/decorators.js +74 -0
- package/dist/utils/decorators.js.map +1 -0
- package/dist/utils/tester.d.ts +2 -0
- package/dist/utils/tester.js +27 -0
- package/dist/utils/tester.js.map +1 -0
- package/eslint.config.mjs +38 -2
- package/jest.config.ts +12 -0
- package/package.json +22 -14
- package/src/index.ts +1 -1
- package/src/rules/graphql/graphql-field-config-from-types.spec.ts +242 -0
- package/src/rules/graphql/graphql-field-config-from-types.ts +557 -0
- package/src/rules/graphql/graphql-field-definite-assignment.spec.ts +135 -0
- package/src/rules/graphql/graphql-field-definite-assignment.ts +147 -0
- package/src/rules/import/import-bullmq.spec.ts +69 -0
- package/src/rules/import/import-bullmq.ts +35 -0
- package/src/rules/import/import-graphql.spec.ts +65 -0
- package/src/rules/import/import-graphql.ts +36 -0
- package/src/rules/import/import-mikro-orm.spec.ts +65 -0
- package/src/rules/import/import-mikro-orm.ts +36 -0
- package/src/rules/index.ts +15 -13
- package/src/rules/mikro-orm/entity-field-definite-assignment.spec.ts +91 -0
- package/src/rules/mikro-orm/entity-field-definite-assignment.ts +141 -0
- package/src/rules/mikro-orm/entity-property-config-from-types.spec.ts +262 -0
- package/src/rules/mikro-orm/entity-property-config-from-types.ts +1111 -0
- package/src/utils/createRule.ts +3 -1
- package/src/utils/decorators.spec.ts +214 -0
- package/src/utils/decorators.ts +93 -0
- package/src/utils/tester.ts +22 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +6 -7
- package/dist/rules/entity-constructor.js +0 -78
- package/dist/rules/entity-constructor.js.map +0 -1
- package/dist/rules/entity-property-no-optional-or-non-null-assertion.js +0 -63
- package/dist/rules/entity-property-no-optional-or-non-null-assertion.js.map +0 -1
- package/dist/rules/entity-property-nullable.js +0 -81
- package/dist/rules/entity-property-nullable.js.map +0 -1
- package/dist/rules/graphql-field-arguments-match-property-type.js +0 -118
- package/dist/rules/graphql-field-arguments-match-property-type.js.map +0 -1
- package/dist/rules/graphql-resolver-method-return-type.js +0 -145
- package/dist/rules/graphql-resolver-method-return-type.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/rules/entity-constructor.ts +0 -97
- package/src/rules/entity-property-no-optional-or-non-null-assertion.ts +0 -81
- package/src/rules/entity-property-nullable.ts +0 -112
- package/src/rules/graphql-field-arguments-match-property-type.ts +0 -186
- package/src/rules/graphql-resolver-method-return-type.ts +0 -207
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const createRule_1 = require("../../utils/createRule");
|
|
4
|
+
exports.default = (0, createRule_1.createRule)({
|
|
5
|
+
name: "import-bullmq",
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: {
|
|
9
|
+
description: "将从 @nestjs/bullmq 导入的包修复为从 @nest-boot/bullmq 导入",
|
|
10
|
+
},
|
|
11
|
+
fixable: "code",
|
|
12
|
+
schema: [],
|
|
13
|
+
messages: {
|
|
14
|
+
replaceBullmqImport: "应从 @nest-boot/bullmq 导入,而不是 @nestjs/bullmq",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration(node) {
|
|
21
|
+
// 检查是否从 @nestjs/bullmq 导入
|
|
22
|
+
if (node.source.value === "@nestjs/bullmq") {
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "replaceBullmqImport",
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
// 将导入源替换为 @nest-boot/bullmq
|
|
28
|
+
return fixer.replaceText(node.source, '"@nest-boot/bullmq"');
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=import-bullmq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-bullmq.js","sourceRoot":"","sources":["../../../src/rules/import/import-bullmq.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AAEpD,kBAAe,IAAA,uBAAU,EAAC;IACxB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,iDAAiD;SACpD;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,mBAAmB,EAAE,4CAA4C;SAClE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,iBAAiB,CAAC,IAAI;gBACpB,0BAA0B;gBAC1B,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;oBAC3C,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAE,qBAAqB;wBAChC,GAAG,CAAC,KAAK;4BACP,4BAA4B;4BAC5B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;wBAC/D,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const createRule_1 = require("../../utils/createRule");
|
|
4
|
+
exports.default = (0, createRule_1.createRule)({
|
|
5
|
+
name: "import-graphql",
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: {
|
|
9
|
+
description: "将从 @nestjs/graphql 导入的包修复为从 @nest-boot/graphql 导入",
|
|
10
|
+
},
|
|
11
|
+
fixable: "code",
|
|
12
|
+
schema: [],
|
|
13
|
+
messages: {
|
|
14
|
+
replaceGraphqlImport: "应从 @nest-boot/graphql 导入,而不是 @nestjs/graphql",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration(node) {
|
|
21
|
+
// 检查是否从 @nestjs/graphql 导入
|
|
22
|
+
if (node.source.value === "@nestjs/graphql") {
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "replaceGraphqlImport",
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
// 将导入源替换为 @nest-boot/graphql
|
|
28
|
+
return fixer.replaceText(node.source, '"@nest-boot/graphql"');
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=import-graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-graphql.js","sourceRoot":"","sources":["../../../src/rules/import/import-graphql.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AAEpD,kBAAe,IAAA,uBAAU,EAAC;IACxB,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,mDAAmD;SACtD;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,oBAAoB,EAClB,8CAA8C;SACjD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,iBAAiB,CAAC,IAAI;gBACpB,2BAA2B;gBAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,iBAAiB,EAAE,CAAC;oBAC5C,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAE,sBAAsB;wBACjC,GAAG,CAAC,KAAK;4BACP,6BAA6B;4BAC7B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;wBAChE,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const createRule_1 = require("../../utils/createRule");
|
|
4
|
+
exports.default = (0, createRule_1.createRule)({
|
|
5
|
+
name: "import-mikro-orm",
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: {
|
|
9
|
+
description: "将从 @mikro-orm/nestjs 导入的包修复为从 @nest-boot/mikro-orm 导入",
|
|
10
|
+
},
|
|
11
|
+
fixable: "code",
|
|
12
|
+
schema: [],
|
|
13
|
+
messages: {
|
|
14
|
+
replaceMikroOrmImport: "应从 @nest-boot/mikro-orm 导入,而不是 @mikro-orm/nestjs",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration(node) {
|
|
21
|
+
// 检查是否从 @mikro-orm/nestjs 导入
|
|
22
|
+
if (node.source.value === "@mikro-orm/nestjs") {
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "replaceMikroOrmImport",
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
// 将导入源替换为 @nest-boot/mikro-orm
|
|
28
|
+
return fixer.replaceText(node.source, '"@nest-boot/mikro-orm"');
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=import-mikro-orm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-mikro-orm.js","sourceRoot":"","sources":["../../../src/rules/import/import-mikro-orm.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AAEpD,kBAAe,IAAA,uBAAU,EAAC;IACxB,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,uDAAuD;SAC1D;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,qBAAqB,EACnB,kDAAkD;SACrD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,iBAAiB,CAAC,IAAI;gBACpB,6BAA6B;gBAC7B,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,mBAAmB,EAAE,CAAC;oBAC9C,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAE,uBAAuB;wBAClC,GAAG,CAAC,KAAK;4BACP,+BAA+B;4BAC/B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;wBAClE,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const rules: {
|
|
2
|
+
"graphql-field-config-from-types": import("@typescript-eslint/utils/ts-eslint").RuleModule<"alignFieldDecoratorWithTsType" | "removeFieldDecorator", [import("./graphql/graphql-field-config-from-types").Options], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
3
|
+
"entity-property-config-from-types": import("@typescript-eslint/utils/ts-eslint").RuleModule<"alignPropertyDecoratorWithTsType" | "removePropertyDecorator" | "useEnumDecorator" | "useOptTypeForInitializedProperty" | "removeOptTypeForNonInitializedProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
4
|
+
"graphql-field-definite-assignment": import("@typescript-eslint/utils/ts-eslint").RuleModule<"addDefiniteAssignment" | "removeDefiniteAssignment", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
5
|
+
"entity-field-definite-assignment": import("@typescript-eslint/utils/ts-eslint").RuleModule<"addDefiniteAssignment" | "removeDefiniteAssignment", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
6
|
+
"import-bullmq": import("@typescript-eslint/utils/ts-eslint").RuleModule<"replaceBullmqImport", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
7
|
+
"import-graphql": import("@typescript-eslint/utils/ts-eslint").RuleModule<"replaceGraphqlImport", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
8
|
+
"import-mikro-orm": import("@typescript-eslint/utils/ts-eslint").RuleModule<"replaceMikroOrmImport", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
|
+
};
|
package/dist/rules/index.js
CHANGED
|
@@ -3,16 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"graphql-field-
|
|
16
|
-
"
|
|
6
|
+
exports.rules = void 0;
|
|
7
|
+
const graphql_field_config_from_types_1 = __importDefault(require("./graphql/graphql-field-config-from-types"));
|
|
8
|
+
const graphql_field_definite_assignment_1 = __importDefault(require("./graphql/graphql-field-definite-assignment"));
|
|
9
|
+
const import_bullmq_1 = __importDefault(require("./import/import-bullmq"));
|
|
10
|
+
const import_graphql_1 = __importDefault(require("./import/import-graphql"));
|
|
11
|
+
const import_mikro_orm_1 = __importDefault(require("./import/import-mikro-orm"));
|
|
12
|
+
const entity_field_definite_assignment_1 = __importDefault(require("./mikro-orm/entity-field-definite-assignment"));
|
|
13
|
+
const entity_property_config_from_types_1 = __importDefault(require("./mikro-orm/entity-property-config-from-types"));
|
|
14
|
+
exports.rules = {
|
|
15
|
+
"graphql-field-config-from-types": graphql_field_config_from_types_1.default,
|
|
16
|
+
"entity-property-config-from-types": entity_property_config_from_types_1.default,
|
|
17
|
+
"graphql-field-definite-assignment": graphql_field_definite_assignment_1.default,
|
|
18
|
+
"entity-field-definite-assignment": entity_field_definite_assignment_1.default,
|
|
19
|
+
"import-bullmq": import_bullmq_1.default,
|
|
20
|
+
"import-graphql": import_graphql_1.default,
|
|
21
|
+
"import-mikro-orm": import_mikro_orm_1.default,
|
|
17
22
|
};
|
|
18
23
|
//# sourceMappingURL=index.js.map
|
package/dist/rules/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;;AAAA,gHAAoF;AACpF,oHAAyF;AACzF,2EAAkD;AAClD,6EAAoD;AACpD,iFAAuD;AACvD,oHAAyF;AACzF,sHAA0F;AAE7E,QAAA,KAAK,GAAG;IACnB,iCAAiC,EAAE,yCAA2B;IAC9D,mCAAmC,EAAE,2CAA6B;IAClE,mCAAmC,EAAE,2CAA8B;IACnE,kCAAkC,EAAE,0CAA6B;IACjE,eAAe,EAAE,uBAAY;IAC7B,gBAAgB,EAAE,wBAAa;IAC/B,kBAAkB,EAAE,0BAAc;CACnC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const createRule_1 = require("../../utils/createRule");
|
|
5
|
+
const decorators_1 = require("../../utils/decorators");
|
|
6
|
+
exports.default = (0, createRule_1.createRule)({
|
|
7
|
+
name: "entity-field-definite-assignment",
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
fixable: "code",
|
|
11
|
+
schema: [],
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Avoid looping over enums.",
|
|
14
|
+
},
|
|
15
|
+
messages: {
|
|
16
|
+
addDefiniteAssignment: "Add definite assignment assertion (!).",
|
|
17
|
+
removeDefiniteAssignment: "Remove definite assignment assertion (!).",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
const source = context.sourceCode;
|
|
23
|
+
const isEntityClass = (node) => {
|
|
24
|
+
return (0, decorators_1.hasClassDecorator)(node, "Entity");
|
|
25
|
+
};
|
|
26
|
+
const getPropertyName = (member) => {
|
|
27
|
+
if (member.key.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
28
|
+
return member.key.name;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
const hasInitializer = (member) => {
|
|
33
|
+
return !!member.value;
|
|
34
|
+
};
|
|
35
|
+
const hasDefiniteAssignment = (member) => {
|
|
36
|
+
return member.definite;
|
|
37
|
+
};
|
|
38
|
+
const isOptionalProperty = (member) => {
|
|
39
|
+
// 检查 AST 节点的 optional 标记
|
|
40
|
+
if (member.optional)
|
|
41
|
+
return true;
|
|
42
|
+
// 检查源代码中是否有 ? 符号(在属性名和冒号之间)
|
|
43
|
+
const keyEnd = member.key.range[1];
|
|
44
|
+
const text = source.text;
|
|
45
|
+
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
46
|
+
if (text[i] === "?")
|
|
47
|
+
return true;
|
|
48
|
+
if (text[i] === ":" || text[i] === "!")
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
ClassDeclaration(node) {
|
|
55
|
+
if (!isEntityClass(node))
|
|
56
|
+
return;
|
|
57
|
+
node.body.body.forEach((member) => {
|
|
58
|
+
if (member.type !== utils_1.AST_NODE_TYPES.PropertyDefinition)
|
|
59
|
+
return;
|
|
60
|
+
if (!(0, decorators_1.hasPropertyDecorator)(member, "Property"))
|
|
61
|
+
return;
|
|
62
|
+
const propertyName = getPropertyName(member);
|
|
63
|
+
if (!propertyName)
|
|
64
|
+
return;
|
|
65
|
+
// 可选属性(?:)不需要 definite assignment assertion
|
|
66
|
+
if (isOptionalProperty(member))
|
|
67
|
+
return;
|
|
68
|
+
const hasInit = hasInitializer(member);
|
|
69
|
+
const hasDefinite = hasDefiniteAssignment(member);
|
|
70
|
+
// 情况1: 没有初始化值,但也没有 definite assignment assertion
|
|
71
|
+
if (!hasInit && !hasDefinite) {
|
|
72
|
+
context.report({
|
|
73
|
+
node: member,
|
|
74
|
+
messageId: "addDefiniteAssignment",
|
|
75
|
+
data: {
|
|
76
|
+
propertyName,
|
|
77
|
+
},
|
|
78
|
+
fix: (fixer) => {
|
|
79
|
+
// 找到属性名称的结束位置
|
|
80
|
+
const keyEnd = member.key.range[1];
|
|
81
|
+
// 在属性名称后添加 !
|
|
82
|
+
return fixer.insertTextAfterRange([keyEnd, keyEnd], "!");
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// 情况2: 有初始化值,但也有 definite assignment assertion
|
|
87
|
+
if (hasInit && hasDefinite) {
|
|
88
|
+
context.report({
|
|
89
|
+
node: member,
|
|
90
|
+
messageId: "removeDefiniteAssignment",
|
|
91
|
+
data: {
|
|
92
|
+
propertyName,
|
|
93
|
+
},
|
|
94
|
+
fix: (fixer) => {
|
|
95
|
+
// 找到 ! 的位置并移除
|
|
96
|
+
const keyEnd = member.key.range[1];
|
|
97
|
+
const text = source.text;
|
|
98
|
+
// 查找 ! 的位置(在属性名称和冒号之间)
|
|
99
|
+
let exclamationPos = -1;
|
|
100
|
+
for (let i = keyEnd; i < member.range[1]; i++) {
|
|
101
|
+
if (text[i] === "!") {
|
|
102
|
+
exclamationPos = i;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
// 如果遇到冒号,说明没有 !
|
|
106
|
+
if (text[i] === ":") {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (exclamationPos !== -1) {
|
|
111
|
+
return fixer.removeRange([
|
|
112
|
+
exclamationPos,
|
|
113
|
+
exclamationPos + 1,
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=entity-field-definite-assignment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-field-definite-assignment.js","sourceRoot":"","sources":["../../../src/rules/mikro-orm/entity-field-definite-assignment.ts"],"names":[],"mappings":";;AAAA,oDAAoE;AAEpE,uDAAoD;AACpD,uDAGgC;AAEhC,kBAAe,IAAA,uBAAU,EAAC;IACxB,IAAI,EAAE,kCAAkC;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;QACV,IAAI,EAAE;YACJ,WAAW,EAAE,2BAA2B;SACzC;QACD,QAAQ,EAAE;YACR,qBAAqB,EAAE,wCAAwC;YAC/D,wBAAwB,EAAE,2CAA2C;SACtE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;QAElC,MAAM,aAAa,GAAG,CAAC,IAA+B,EAAW,EAAE;YACjE,OAAO,IAAA,8BAAiB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC;QAEF,MAAM,eAAe,GAAG,CACtB,MAAmC,EACpB,EAAE;YACjB,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,sBAAc,CAAC,UAAU,EAA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B,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;oCAC9C,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;wCACpB,cAAc,GAAG,CAAC,CAAC;wCACnB,MAAM;oCACR,CAAC;oCACD,gBAAgB;oCAChB,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;wCACpB,MAAM;oCACR,CAAC;gCACH,CAAC;gCAED,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;oCAC1B,OAAO,KAAK,CAAC,WAAW,CAAC;wCACvB,cAAc;wCACd,cAAc,GAAG,CAAC;qCACnB,CAAC,CAAC;gCACL,CAAC;gCACD,OAAO,IAAI,CAAC;4BACd,CAAC;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
declare const _default: ESLintUtils.RuleModule<"alignPropertyDecoratorWithTsType" | "removePropertyDecorator" | "useEnumDecorator" | "useOptTypeForInitializedProperty" | "removeOptTypeForNonInitializedProperty", [], unknown, ESLintUtils.RuleListener>;
|
|
3
|
+
export default _default;
|