eslint-cdk-plugin 2.0.0 → 2.1.0
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/dist/index.cjs +66 -41
- package/dist/index.d.ts +11 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +66 -41
- package/package.json +1 -1
- package/src/index.ts +1 -2
- package/src/rules/no-parent-name-construct-id-match.ts +43 -9
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
26
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
27
|
|
|
28
28
|
var name = "eslint-cdk-plugin";
|
|
29
|
-
var version = "
|
|
29
|
+
var version = "2.0.1";
|
|
30
30
|
|
|
31
31
|
const isConstructOrStackType = (type, ignoredClasses = ["App", "Stage"]) => {
|
|
32
32
|
if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
|
|
@@ -410,8 +410,11 @@ const noParentNameConstructIdMatch = utils.ESLintUtils.RuleCreator.withoutDocs(
|
|
|
410
410
|
},
|
|
411
411
|
defaultOptions: [],
|
|
412
412
|
create(context) {
|
|
413
|
+
const parserServices = utils.ESLintUtils.getParserServices(context);
|
|
413
414
|
return {
|
|
414
415
|
ClassBody(node) {
|
|
416
|
+
const type = parserServices.getTypeAtLocation(node);
|
|
417
|
+
if (!isConstructOrStackType(type)) return;
|
|
415
418
|
const parent = node.parent;
|
|
416
419
|
if (parent?.type !== utils.AST_NODE_TYPES.ClassDeclaration) return;
|
|
417
420
|
const parentClassName = parent.id?.name;
|
|
@@ -424,7 +427,8 @@ const noParentNameConstructIdMatch = utils.ESLintUtils.RuleCreator.withoutDocs(
|
|
|
424
427
|
node,
|
|
425
428
|
expression: body.value,
|
|
426
429
|
parentClassName,
|
|
427
|
-
context
|
|
430
|
+
context,
|
|
431
|
+
parserServices
|
|
428
432
|
});
|
|
429
433
|
}
|
|
430
434
|
}
|
|
@@ -436,7 +440,8 @@ const validateConstructorBody = ({
|
|
|
436
440
|
node,
|
|
437
441
|
expression,
|
|
438
442
|
parentClassName,
|
|
439
|
-
context
|
|
443
|
+
context,
|
|
444
|
+
parserServices
|
|
440
445
|
}) => {
|
|
441
446
|
for (const statement of expression.body.body) {
|
|
442
447
|
switch (statement.type) {
|
|
@@ -447,7 +452,8 @@ const validateConstructorBody = ({
|
|
|
447
452
|
node,
|
|
448
453
|
context,
|
|
449
454
|
expression: newExpression,
|
|
450
|
-
parentClassName
|
|
455
|
+
parentClassName,
|
|
456
|
+
parserServices
|
|
451
457
|
});
|
|
452
458
|
break;
|
|
453
459
|
}
|
|
@@ -457,7 +463,8 @@ const validateConstructorBody = ({
|
|
|
457
463
|
node,
|
|
458
464
|
statement,
|
|
459
465
|
parentClassName,
|
|
460
|
-
context
|
|
466
|
+
context,
|
|
467
|
+
parserServices
|
|
461
468
|
});
|
|
462
469
|
break;
|
|
463
470
|
}
|
|
@@ -466,7 +473,8 @@ const validateConstructorBody = ({
|
|
|
466
473
|
node,
|
|
467
474
|
context,
|
|
468
475
|
parentClassName,
|
|
469
|
-
statement: statement.consequent
|
|
476
|
+
statement: statement.consequent,
|
|
477
|
+
parserServices
|
|
470
478
|
});
|
|
471
479
|
break;
|
|
472
480
|
}
|
|
@@ -477,7 +485,8 @@ const validateConstructorBody = ({
|
|
|
477
485
|
node,
|
|
478
486
|
context,
|
|
479
487
|
parentClassName,
|
|
480
|
-
statement: statement2
|
|
488
|
+
statement: statement2,
|
|
489
|
+
parserServices
|
|
481
490
|
});
|
|
482
491
|
}
|
|
483
492
|
}
|
|
@@ -490,7 +499,8 @@ const traverseStatements = ({
|
|
|
490
499
|
node,
|
|
491
500
|
statement,
|
|
492
501
|
parentClassName,
|
|
493
|
-
context
|
|
502
|
+
context,
|
|
503
|
+
parserServices
|
|
494
504
|
}) => {
|
|
495
505
|
switch (statement.type) {
|
|
496
506
|
case utils.AST_NODE_TYPES.BlockStatement: {
|
|
@@ -499,7 +509,8 @@ const traverseStatements = ({
|
|
|
499
509
|
node,
|
|
500
510
|
statement: body,
|
|
501
511
|
parentClassName,
|
|
502
|
-
context
|
|
512
|
+
context,
|
|
513
|
+
parserServices
|
|
503
514
|
});
|
|
504
515
|
}
|
|
505
516
|
break;
|
|
@@ -511,7 +522,8 @@ const traverseStatements = ({
|
|
|
511
522
|
node,
|
|
512
523
|
statement,
|
|
513
524
|
parentClassName,
|
|
514
|
-
context
|
|
525
|
+
context,
|
|
526
|
+
parserServices
|
|
515
527
|
});
|
|
516
528
|
break;
|
|
517
529
|
}
|
|
@@ -522,7 +534,8 @@ const traverseStatements = ({
|
|
|
522
534
|
node,
|
|
523
535
|
context,
|
|
524
536
|
expression: newExpression,
|
|
525
|
-
parentClassName
|
|
537
|
+
parentClassName,
|
|
538
|
+
parserServices
|
|
526
539
|
});
|
|
527
540
|
break;
|
|
528
541
|
}
|
|
@@ -532,7 +545,8 @@ const validateStatement = ({
|
|
|
532
545
|
node,
|
|
533
546
|
statement,
|
|
534
547
|
parentClassName,
|
|
535
|
-
context
|
|
548
|
+
context,
|
|
549
|
+
parserServices
|
|
536
550
|
}) => {
|
|
537
551
|
switch (statement.type) {
|
|
538
552
|
case utils.AST_NODE_TYPES.VariableDeclaration: {
|
|
@@ -542,7 +556,8 @@ const validateStatement = ({
|
|
|
542
556
|
node,
|
|
543
557
|
context,
|
|
544
558
|
expression: newExpression,
|
|
545
|
-
parentClassName
|
|
559
|
+
parentClassName,
|
|
560
|
+
parserServices
|
|
546
561
|
});
|
|
547
562
|
break;
|
|
548
563
|
}
|
|
@@ -553,7 +568,8 @@ const validateStatement = ({
|
|
|
553
568
|
node,
|
|
554
569
|
context,
|
|
555
570
|
expression: newExpression,
|
|
556
|
-
parentClassName
|
|
571
|
+
parentClassName,
|
|
572
|
+
parserServices
|
|
557
573
|
});
|
|
558
574
|
break;
|
|
559
575
|
}
|
|
@@ -562,7 +578,8 @@ const validateStatement = ({
|
|
|
562
578
|
node,
|
|
563
579
|
statement,
|
|
564
580
|
parentClassName,
|
|
565
|
-
context
|
|
581
|
+
context,
|
|
582
|
+
parserServices
|
|
566
583
|
});
|
|
567
584
|
break;
|
|
568
585
|
}
|
|
@@ -571,7 +588,8 @@ const validateStatement = ({
|
|
|
571
588
|
node,
|
|
572
589
|
statement,
|
|
573
590
|
parentClassName,
|
|
574
|
-
context
|
|
591
|
+
context,
|
|
592
|
+
parserServices
|
|
575
593
|
});
|
|
576
594
|
break;
|
|
577
595
|
}
|
|
@@ -581,20 +599,23 @@ const validateIfStatement = ({
|
|
|
581
599
|
node,
|
|
582
600
|
statement,
|
|
583
601
|
parentClassName,
|
|
584
|
-
context
|
|
602
|
+
context,
|
|
603
|
+
parserServices
|
|
585
604
|
}) => {
|
|
586
605
|
traverseStatements({
|
|
587
606
|
node,
|
|
588
607
|
context,
|
|
589
608
|
parentClassName,
|
|
590
|
-
statement: statement.consequent
|
|
609
|
+
statement: statement.consequent,
|
|
610
|
+
parserServices
|
|
591
611
|
});
|
|
592
612
|
};
|
|
593
613
|
const validateSwitchStatement = ({
|
|
594
614
|
node,
|
|
595
615
|
statement,
|
|
596
616
|
parentClassName,
|
|
597
|
-
context
|
|
617
|
+
context,
|
|
618
|
+
parserServices
|
|
598
619
|
}) => {
|
|
599
620
|
for (const caseStatement of statement.cases) {
|
|
600
621
|
for (const _consequent of caseStatement.consequent) {
|
|
@@ -602,7 +623,8 @@ const validateSwitchStatement = ({
|
|
|
602
623
|
node,
|
|
603
624
|
context,
|
|
604
625
|
parentClassName,
|
|
605
|
-
statement: _consequent
|
|
626
|
+
statement: _consequent,
|
|
627
|
+
parserServices
|
|
606
628
|
});
|
|
607
629
|
}
|
|
608
630
|
}
|
|
@@ -611,8 +633,10 @@ const validateConstructId$2 = ({
|
|
|
611
633
|
node,
|
|
612
634
|
context,
|
|
613
635
|
expression,
|
|
614
|
-
parentClassName
|
|
636
|
+
parentClassName,
|
|
637
|
+
parserServices
|
|
615
638
|
}) => {
|
|
639
|
+
const type = parserServices.getTypeAtLocation(expression);
|
|
616
640
|
if (expression.arguments.length < 2) return;
|
|
617
641
|
const secondArg = expression.arguments[1];
|
|
618
642
|
if (secondArg.type !== utils.AST_NODE_TYPES.Literal || typeof secondArg.value !== "string") {
|
|
@@ -620,15 +644,17 @@ const validateConstructId$2 = ({
|
|
|
620
644
|
}
|
|
621
645
|
const formattedConstructId = toPascalCase(secondArg.value);
|
|
622
646
|
const formattedParentClassName = toPascalCase(parentClassName);
|
|
623
|
-
if (
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
647
|
+
if (!isConstructType(type)) return;
|
|
648
|
+
if (formattedConstructId.includes(formattedParentClassName)) {
|
|
649
|
+
context.report({
|
|
650
|
+
node,
|
|
651
|
+
messageId: "noParentNameConstructIdMatch",
|
|
652
|
+
data: {
|
|
653
|
+
constructId: secondArg.value,
|
|
654
|
+
parentConstructName: parentClassName
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
632
658
|
};
|
|
633
659
|
|
|
634
660
|
const noPublicClassFields = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
@@ -1046,16 +1072,16 @@ const requirePropsDefaultDoc = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
1046
1072
|
});
|
|
1047
1073
|
|
|
1048
1074
|
const rules = {
|
|
1049
|
-
"construct-constructor-property": constructConstructorProperty,
|
|
1050
1075
|
"no-class-in-interface": noClassInInterface,
|
|
1051
1076
|
"no-construct-stack-suffix": noConstructStackSuffix,
|
|
1052
1077
|
"no-parent-name-construct-id-match": noParentNameConstructIdMatch,
|
|
1053
1078
|
"no-public-class-fields": noPublicClassFields,
|
|
1054
1079
|
"pascal-case-construct-id": pascalCaseConstructId,
|
|
1055
|
-
"no-mutable-public-fields": noMutablePublicFields,
|
|
1056
|
-
"no-mutable-props-interface": noMutablePropsInterface,
|
|
1057
1080
|
"require-passing-this": requirePassingThis,
|
|
1058
1081
|
"no-variable-construct-id": noVariableConstructId,
|
|
1082
|
+
"no-mutable-public-fields": noMutablePublicFields,
|
|
1083
|
+
"no-mutable-props-interface": noMutablePropsInterface,
|
|
1084
|
+
"construct-constructor-property": constructConstructorProperty,
|
|
1059
1085
|
"require-jsdoc": requireJSDoc,
|
|
1060
1086
|
"require-props-default-doc": requirePropsDefaultDoc,
|
|
1061
1087
|
"props-name-convention": propsNameConvention,
|
|
@@ -1068,10 +1094,9 @@ const cdkPlugin = {
|
|
|
1068
1094
|
const createFlatConfig = (rules2) => {
|
|
1069
1095
|
return {
|
|
1070
1096
|
languageOptions: {
|
|
1097
|
+
parser: tsParser,
|
|
1071
1098
|
parserOptions: {
|
|
1072
|
-
projectService: true
|
|
1073
|
-
parser: tsParser,
|
|
1074
|
-
sourceType: "module"
|
|
1099
|
+
projectService: true
|
|
1075
1100
|
}
|
|
1076
1101
|
},
|
|
1077
1102
|
plugins: {
|
|
@@ -1081,7 +1106,6 @@ const createFlatConfig = (rules2) => {
|
|
|
1081
1106
|
};
|
|
1082
1107
|
};
|
|
1083
1108
|
const recommended = createFlatConfig({
|
|
1084
|
-
"cdk/construct-constructor-property": "error",
|
|
1085
1109
|
"cdk/no-class-in-interface": "error",
|
|
1086
1110
|
"cdk/no-construct-stack-suffix": "error",
|
|
1087
1111
|
"cdk/no-parent-name-construct-id-match": "error",
|
|
@@ -1090,10 +1114,10 @@ const recommended = createFlatConfig({
|
|
|
1090
1114
|
"cdk/require-passing-this": ["error", { allowNonThisAndDisallowScope: true }],
|
|
1091
1115
|
"cdk/no-variable-construct-id": "error",
|
|
1092
1116
|
"cdk/no-mutable-public-fields": "warn",
|
|
1093
|
-
"cdk/no-mutable-props-interface": "warn"
|
|
1117
|
+
"cdk/no-mutable-props-interface": "warn",
|
|
1118
|
+
"cdk/construct-constructor-property": "error"
|
|
1094
1119
|
});
|
|
1095
1120
|
const strict = createFlatConfig({
|
|
1096
|
-
"cdk/construct-constructor-property": "error",
|
|
1097
1121
|
"cdk/no-class-in-interface": "error",
|
|
1098
1122
|
"cdk/no-construct-stack-suffix": "error",
|
|
1099
1123
|
"cdk/no-parent-name-construct-id-match": "error",
|
|
@@ -1103,10 +1127,11 @@ const strict = createFlatConfig({
|
|
|
1103
1127
|
"cdk/no-variable-construct-id": "error",
|
|
1104
1128
|
"cdk/no-mutable-public-fields": "error",
|
|
1105
1129
|
"cdk/no-mutable-props-interface": "error",
|
|
1106
|
-
"cdk/
|
|
1130
|
+
"cdk/construct-constructor-property": "error",
|
|
1131
|
+
"cdk/require-jsdoc": "error",
|
|
1107
1132
|
"cdk/require-props-default-doc": "error",
|
|
1108
1133
|
"cdk/props-name-convention": "error",
|
|
1109
|
-
"cdk/
|
|
1134
|
+
"cdk/no-import-private": "error"
|
|
1110
1135
|
});
|
|
1111
1136
|
const configs = {
|
|
1112
1137
|
recommended,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import tsParser from "@typescript-eslint/parser";
|
|
2
2
|
declare const rules: {
|
|
3
|
-
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
4
3
|
"no-class-in-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noClassInInterfaceProps", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
5
4
|
"no-construct-stack-suffix": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConstructStackSuffix", [{
|
|
6
5
|
disallowedSuffixes: ("Construct" | "Stack")[];
|
|
@@ -8,12 +7,13 @@ declare const rules: {
|
|
|
8
7
|
"no-parent-name-construct-id-match": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noParentNameConstructIdMatch", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
8
|
"no-public-class-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noPublicClassFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
10
9
|
"pascal-case-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"pascalCaseConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
11
|
-
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
12
|
-
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
13
10
|
"require-passing-this": import("@typescript-eslint/utils/ts-eslint").RuleModule<"requirePassingThis", [{
|
|
14
11
|
allowNonThisAndDisallowScope?: boolean;
|
|
15
12
|
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
16
13
|
"no-variable-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noVariableConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
14
|
+
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
15
|
+
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
16
|
+
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
17
17
|
"require-jsdoc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingJSDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
18
18
|
"require-props-default-doc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDefaultDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
19
19
|
"props-name-convention": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidPropsName", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
@@ -22,10 +22,9 @@ declare const rules: {
|
|
|
22
22
|
declare const configs: {
|
|
23
23
|
recommended: {
|
|
24
24
|
languageOptions: {
|
|
25
|
+
parser: typeof tsParser;
|
|
25
26
|
parserOptions: {
|
|
26
27
|
projectService: boolean;
|
|
27
|
-
parser: typeof tsParser;
|
|
28
|
-
sourceType: string;
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
30
|
plugins: {
|
|
@@ -35,7 +34,6 @@ declare const configs: {
|
|
|
35
34
|
version: string;
|
|
36
35
|
};
|
|
37
36
|
rules: {
|
|
38
|
-
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
39
37
|
"no-class-in-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noClassInInterfaceProps", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
40
38
|
"no-construct-stack-suffix": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConstructStackSuffix", [{
|
|
41
39
|
disallowedSuffixes: ("Construct" | "Stack")[];
|
|
@@ -43,12 +41,13 @@ declare const configs: {
|
|
|
43
41
|
"no-parent-name-construct-id-match": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noParentNameConstructIdMatch", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
44
42
|
"no-public-class-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noPublicClassFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
45
43
|
"pascal-case-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"pascalCaseConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
46
|
-
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
47
|
-
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
48
44
|
"require-passing-this": import("@typescript-eslint/utils/ts-eslint").RuleModule<"requirePassingThis", [{
|
|
49
45
|
allowNonThisAndDisallowScope?: boolean;
|
|
50
46
|
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
51
47
|
"no-variable-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noVariableConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
48
|
+
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
49
|
+
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
50
|
+
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
52
51
|
"require-jsdoc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingJSDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
53
52
|
"require-props-default-doc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDefaultDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
54
53
|
"props-name-convention": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidPropsName", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
@@ -60,10 +59,9 @@ declare const configs: {
|
|
|
60
59
|
};
|
|
61
60
|
strict: {
|
|
62
61
|
languageOptions: {
|
|
62
|
+
parser: typeof tsParser;
|
|
63
63
|
parserOptions: {
|
|
64
64
|
projectService: boolean;
|
|
65
|
-
parser: typeof tsParser;
|
|
66
|
-
sourceType: string;
|
|
67
65
|
};
|
|
68
66
|
};
|
|
69
67
|
plugins: {
|
|
@@ -73,7 +71,6 @@ declare const configs: {
|
|
|
73
71
|
version: string;
|
|
74
72
|
};
|
|
75
73
|
rules: {
|
|
76
|
-
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
77
74
|
"no-class-in-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noClassInInterfaceProps", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
78
75
|
"no-construct-stack-suffix": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConstructStackSuffix", [{
|
|
79
76
|
disallowedSuffixes: ("Construct" | "Stack")[];
|
|
@@ -81,12 +78,13 @@ declare const configs: {
|
|
|
81
78
|
"no-parent-name-construct-id-match": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noParentNameConstructIdMatch", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
82
79
|
"no-public-class-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noPublicClassFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
83
80
|
"pascal-case-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"pascalCaseConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
84
|
-
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
85
|
-
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
86
81
|
"require-passing-this": import("@typescript-eslint/utils/ts-eslint").RuleModule<"requirePassingThis", [{
|
|
87
82
|
allowNonThisAndDisallowScope?: boolean;
|
|
88
83
|
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
89
84
|
"no-variable-construct-id": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noVariableConstructId", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
85
|
+
"no-mutable-public-fields": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePublicFields", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
86
|
+
"no-mutable-props-interface": import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMutablePropsInterface", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
87
|
+
"construct-constructor-property": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidConstructorProperty", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
90
88
|
"require-jsdoc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingJSDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
91
89
|
"require-props-default-doc": import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDefaultDoc", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
92
90
|
"props-name-convention": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidPropsName", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,2BAA2B,CAAC;AAmBjD,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;CAeV,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,2BAA2B,CAAC;AAmBjD,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;CAeV,CAAC;AAoDF,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAE1B,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,OAAO,EAAE,OAAO,OAAO,CAAC;CACzB;AAED,QAAA,MAAM,eAAe,EAAE,eAGtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ESLintUtils, AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
|
|
5
5
|
var name = "eslint-cdk-plugin";
|
|
6
|
-
var version = "
|
|
6
|
+
var version = "2.0.1";
|
|
7
7
|
|
|
8
8
|
const isConstructOrStackType = (type, ignoredClasses = ["App", "Stage"]) => {
|
|
9
9
|
if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
|
|
@@ -387,8 +387,11 @@ const noParentNameConstructIdMatch = ESLintUtils.RuleCreator.withoutDocs(
|
|
|
387
387
|
},
|
|
388
388
|
defaultOptions: [],
|
|
389
389
|
create(context) {
|
|
390
|
+
const parserServices = ESLintUtils.getParserServices(context);
|
|
390
391
|
return {
|
|
391
392
|
ClassBody(node) {
|
|
393
|
+
const type = parserServices.getTypeAtLocation(node);
|
|
394
|
+
if (!isConstructOrStackType(type)) return;
|
|
392
395
|
const parent = node.parent;
|
|
393
396
|
if (parent?.type !== AST_NODE_TYPES.ClassDeclaration) return;
|
|
394
397
|
const parentClassName = parent.id?.name;
|
|
@@ -401,7 +404,8 @@ const noParentNameConstructIdMatch = ESLintUtils.RuleCreator.withoutDocs(
|
|
|
401
404
|
node,
|
|
402
405
|
expression: body.value,
|
|
403
406
|
parentClassName,
|
|
404
|
-
context
|
|
407
|
+
context,
|
|
408
|
+
parserServices
|
|
405
409
|
});
|
|
406
410
|
}
|
|
407
411
|
}
|
|
@@ -413,7 +417,8 @@ const validateConstructorBody = ({
|
|
|
413
417
|
node,
|
|
414
418
|
expression,
|
|
415
419
|
parentClassName,
|
|
416
|
-
context
|
|
420
|
+
context,
|
|
421
|
+
parserServices
|
|
417
422
|
}) => {
|
|
418
423
|
for (const statement of expression.body.body) {
|
|
419
424
|
switch (statement.type) {
|
|
@@ -424,7 +429,8 @@ const validateConstructorBody = ({
|
|
|
424
429
|
node,
|
|
425
430
|
context,
|
|
426
431
|
expression: newExpression,
|
|
427
|
-
parentClassName
|
|
432
|
+
parentClassName,
|
|
433
|
+
parserServices
|
|
428
434
|
});
|
|
429
435
|
break;
|
|
430
436
|
}
|
|
@@ -434,7 +440,8 @@ const validateConstructorBody = ({
|
|
|
434
440
|
node,
|
|
435
441
|
statement,
|
|
436
442
|
parentClassName,
|
|
437
|
-
context
|
|
443
|
+
context,
|
|
444
|
+
parserServices
|
|
438
445
|
});
|
|
439
446
|
break;
|
|
440
447
|
}
|
|
@@ -443,7 +450,8 @@ const validateConstructorBody = ({
|
|
|
443
450
|
node,
|
|
444
451
|
context,
|
|
445
452
|
parentClassName,
|
|
446
|
-
statement: statement.consequent
|
|
453
|
+
statement: statement.consequent,
|
|
454
|
+
parserServices
|
|
447
455
|
});
|
|
448
456
|
break;
|
|
449
457
|
}
|
|
@@ -454,7 +462,8 @@ const validateConstructorBody = ({
|
|
|
454
462
|
node,
|
|
455
463
|
context,
|
|
456
464
|
parentClassName,
|
|
457
|
-
statement: statement2
|
|
465
|
+
statement: statement2,
|
|
466
|
+
parserServices
|
|
458
467
|
});
|
|
459
468
|
}
|
|
460
469
|
}
|
|
@@ -467,7 +476,8 @@ const traverseStatements = ({
|
|
|
467
476
|
node,
|
|
468
477
|
statement,
|
|
469
478
|
parentClassName,
|
|
470
|
-
context
|
|
479
|
+
context,
|
|
480
|
+
parserServices
|
|
471
481
|
}) => {
|
|
472
482
|
switch (statement.type) {
|
|
473
483
|
case AST_NODE_TYPES.BlockStatement: {
|
|
@@ -476,7 +486,8 @@ const traverseStatements = ({
|
|
|
476
486
|
node,
|
|
477
487
|
statement: body,
|
|
478
488
|
parentClassName,
|
|
479
|
-
context
|
|
489
|
+
context,
|
|
490
|
+
parserServices
|
|
480
491
|
});
|
|
481
492
|
}
|
|
482
493
|
break;
|
|
@@ -488,7 +499,8 @@ const traverseStatements = ({
|
|
|
488
499
|
node,
|
|
489
500
|
statement,
|
|
490
501
|
parentClassName,
|
|
491
|
-
context
|
|
502
|
+
context,
|
|
503
|
+
parserServices
|
|
492
504
|
});
|
|
493
505
|
break;
|
|
494
506
|
}
|
|
@@ -499,7 +511,8 @@ const traverseStatements = ({
|
|
|
499
511
|
node,
|
|
500
512
|
context,
|
|
501
513
|
expression: newExpression,
|
|
502
|
-
parentClassName
|
|
514
|
+
parentClassName,
|
|
515
|
+
parserServices
|
|
503
516
|
});
|
|
504
517
|
break;
|
|
505
518
|
}
|
|
@@ -509,7 +522,8 @@ const validateStatement = ({
|
|
|
509
522
|
node,
|
|
510
523
|
statement,
|
|
511
524
|
parentClassName,
|
|
512
|
-
context
|
|
525
|
+
context,
|
|
526
|
+
parserServices
|
|
513
527
|
}) => {
|
|
514
528
|
switch (statement.type) {
|
|
515
529
|
case AST_NODE_TYPES.VariableDeclaration: {
|
|
@@ -519,7 +533,8 @@ const validateStatement = ({
|
|
|
519
533
|
node,
|
|
520
534
|
context,
|
|
521
535
|
expression: newExpression,
|
|
522
|
-
parentClassName
|
|
536
|
+
parentClassName,
|
|
537
|
+
parserServices
|
|
523
538
|
});
|
|
524
539
|
break;
|
|
525
540
|
}
|
|
@@ -530,7 +545,8 @@ const validateStatement = ({
|
|
|
530
545
|
node,
|
|
531
546
|
context,
|
|
532
547
|
expression: newExpression,
|
|
533
|
-
parentClassName
|
|
548
|
+
parentClassName,
|
|
549
|
+
parserServices
|
|
534
550
|
});
|
|
535
551
|
break;
|
|
536
552
|
}
|
|
@@ -539,7 +555,8 @@ const validateStatement = ({
|
|
|
539
555
|
node,
|
|
540
556
|
statement,
|
|
541
557
|
parentClassName,
|
|
542
|
-
context
|
|
558
|
+
context,
|
|
559
|
+
parserServices
|
|
543
560
|
});
|
|
544
561
|
break;
|
|
545
562
|
}
|
|
@@ -548,7 +565,8 @@ const validateStatement = ({
|
|
|
548
565
|
node,
|
|
549
566
|
statement,
|
|
550
567
|
parentClassName,
|
|
551
|
-
context
|
|
568
|
+
context,
|
|
569
|
+
parserServices
|
|
552
570
|
});
|
|
553
571
|
break;
|
|
554
572
|
}
|
|
@@ -558,20 +576,23 @@ const validateIfStatement = ({
|
|
|
558
576
|
node,
|
|
559
577
|
statement,
|
|
560
578
|
parentClassName,
|
|
561
|
-
context
|
|
579
|
+
context,
|
|
580
|
+
parserServices
|
|
562
581
|
}) => {
|
|
563
582
|
traverseStatements({
|
|
564
583
|
node,
|
|
565
584
|
context,
|
|
566
585
|
parentClassName,
|
|
567
|
-
statement: statement.consequent
|
|
586
|
+
statement: statement.consequent,
|
|
587
|
+
parserServices
|
|
568
588
|
});
|
|
569
589
|
};
|
|
570
590
|
const validateSwitchStatement = ({
|
|
571
591
|
node,
|
|
572
592
|
statement,
|
|
573
593
|
parentClassName,
|
|
574
|
-
context
|
|
594
|
+
context,
|
|
595
|
+
parserServices
|
|
575
596
|
}) => {
|
|
576
597
|
for (const caseStatement of statement.cases) {
|
|
577
598
|
for (const _consequent of caseStatement.consequent) {
|
|
@@ -579,7 +600,8 @@ const validateSwitchStatement = ({
|
|
|
579
600
|
node,
|
|
580
601
|
context,
|
|
581
602
|
parentClassName,
|
|
582
|
-
statement: _consequent
|
|
603
|
+
statement: _consequent,
|
|
604
|
+
parserServices
|
|
583
605
|
});
|
|
584
606
|
}
|
|
585
607
|
}
|
|
@@ -588,8 +610,10 @@ const validateConstructId$2 = ({
|
|
|
588
610
|
node,
|
|
589
611
|
context,
|
|
590
612
|
expression,
|
|
591
|
-
parentClassName
|
|
613
|
+
parentClassName,
|
|
614
|
+
parserServices
|
|
592
615
|
}) => {
|
|
616
|
+
const type = parserServices.getTypeAtLocation(expression);
|
|
593
617
|
if (expression.arguments.length < 2) return;
|
|
594
618
|
const secondArg = expression.arguments[1];
|
|
595
619
|
if (secondArg.type !== AST_NODE_TYPES.Literal || typeof secondArg.value !== "string") {
|
|
@@ -597,15 +621,17 @@ const validateConstructId$2 = ({
|
|
|
597
621
|
}
|
|
598
622
|
const formattedConstructId = toPascalCase(secondArg.value);
|
|
599
623
|
const formattedParentClassName = toPascalCase(parentClassName);
|
|
600
|
-
if (
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
624
|
+
if (!isConstructType(type)) return;
|
|
625
|
+
if (formattedConstructId.includes(formattedParentClassName)) {
|
|
626
|
+
context.report({
|
|
627
|
+
node,
|
|
628
|
+
messageId: "noParentNameConstructIdMatch",
|
|
629
|
+
data: {
|
|
630
|
+
constructId: secondArg.value,
|
|
631
|
+
parentConstructName: parentClassName
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
}
|
|
609
635
|
};
|
|
610
636
|
|
|
611
637
|
const noPublicClassFields = ESLintUtils.RuleCreator.withoutDocs({
|
|
@@ -1023,16 +1049,16 @@ const requirePropsDefaultDoc = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
1023
1049
|
});
|
|
1024
1050
|
|
|
1025
1051
|
const rules = {
|
|
1026
|
-
"construct-constructor-property": constructConstructorProperty,
|
|
1027
1052
|
"no-class-in-interface": noClassInInterface,
|
|
1028
1053
|
"no-construct-stack-suffix": noConstructStackSuffix,
|
|
1029
1054
|
"no-parent-name-construct-id-match": noParentNameConstructIdMatch,
|
|
1030
1055
|
"no-public-class-fields": noPublicClassFields,
|
|
1031
1056
|
"pascal-case-construct-id": pascalCaseConstructId,
|
|
1032
|
-
"no-mutable-public-fields": noMutablePublicFields,
|
|
1033
|
-
"no-mutable-props-interface": noMutablePropsInterface,
|
|
1034
1057
|
"require-passing-this": requirePassingThis,
|
|
1035
1058
|
"no-variable-construct-id": noVariableConstructId,
|
|
1059
|
+
"no-mutable-public-fields": noMutablePublicFields,
|
|
1060
|
+
"no-mutable-props-interface": noMutablePropsInterface,
|
|
1061
|
+
"construct-constructor-property": constructConstructorProperty,
|
|
1036
1062
|
"require-jsdoc": requireJSDoc,
|
|
1037
1063
|
"require-props-default-doc": requirePropsDefaultDoc,
|
|
1038
1064
|
"props-name-convention": propsNameConvention,
|
|
@@ -1045,10 +1071,9 @@ const cdkPlugin = {
|
|
|
1045
1071
|
const createFlatConfig = (rules2) => {
|
|
1046
1072
|
return {
|
|
1047
1073
|
languageOptions: {
|
|
1074
|
+
parser: tsParser,
|
|
1048
1075
|
parserOptions: {
|
|
1049
|
-
projectService: true
|
|
1050
|
-
parser: tsParser,
|
|
1051
|
-
sourceType: "module"
|
|
1076
|
+
projectService: true
|
|
1052
1077
|
}
|
|
1053
1078
|
},
|
|
1054
1079
|
plugins: {
|
|
@@ -1058,7 +1083,6 @@ const createFlatConfig = (rules2) => {
|
|
|
1058
1083
|
};
|
|
1059
1084
|
};
|
|
1060
1085
|
const recommended = createFlatConfig({
|
|
1061
|
-
"cdk/construct-constructor-property": "error",
|
|
1062
1086
|
"cdk/no-class-in-interface": "error",
|
|
1063
1087
|
"cdk/no-construct-stack-suffix": "error",
|
|
1064
1088
|
"cdk/no-parent-name-construct-id-match": "error",
|
|
@@ -1067,10 +1091,10 @@ const recommended = createFlatConfig({
|
|
|
1067
1091
|
"cdk/require-passing-this": ["error", { allowNonThisAndDisallowScope: true }],
|
|
1068
1092
|
"cdk/no-variable-construct-id": "error",
|
|
1069
1093
|
"cdk/no-mutable-public-fields": "warn",
|
|
1070
|
-
"cdk/no-mutable-props-interface": "warn"
|
|
1094
|
+
"cdk/no-mutable-props-interface": "warn",
|
|
1095
|
+
"cdk/construct-constructor-property": "error"
|
|
1071
1096
|
});
|
|
1072
1097
|
const strict = createFlatConfig({
|
|
1073
|
-
"cdk/construct-constructor-property": "error",
|
|
1074
1098
|
"cdk/no-class-in-interface": "error",
|
|
1075
1099
|
"cdk/no-construct-stack-suffix": "error",
|
|
1076
1100
|
"cdk/no-parent-name-construct-id-match": "error",
|
|
@@ -1080,10 +1104,11 @@ const strict = createFlatConfig({
|
|
|
1080
1104
|
"cdk/no-variable-construct-id": "error",
|
|
1081
1105
|
"cdk/no-mutable-public-fields": "error",
|
|
1082
1106
|
"cdk/no-mutable-props-interface": "error",
|
|
1083
|
-
"cdk/
|
|
1107
|
+
"cdk/construct-constructor-property": "error",
|
|
1108
|
+
"cdk/require-jsdoc": "error",
|
|
1084
1109
|
"cdk/require-props-default-doc": "error",
|
|
1085
1110
|
"cdk/props-name-convention": "error",
|
|
1086
|
-
"cdk/
|
|
1111
|
+
"cdk/no-import-private": "error"
|
|
1087
1112
|
});
|
|
1088
1113
|
const configs = {
|
|
1089
1114
|
recommended,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -42,10 +42,9 @@ const cdkPlugin = {
|
|
|
42
42
|
const createFlatConfig = (rules: Record<string, unknown>) => {
|
|
43
43
|
return {
|
|
44
44
|
languageOptions: {
|
|
45
|
+
parser: tsParser,
|
|
45
46
|
parserOptions: {
|
|
46
47
|
projectService: true,
|
|
47
|
-
parser: tsParser,
|
|
48
|
-
sourceType: "module",
|
|
49
48
|
},
|
|
50
49
|
},
|
|
51
50
|
plugins: {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AST_NODE_TYPES,
|
|
3
3
|
ESLintUtils,
|
|
4
|
+
ParserServicesWithTypeInformation,
|
|
4
5
|
TSESLint,
|
|
5
6
|
TSESTree,
|
|
6
7
|
} from "@typescript-eslint/utils";
|
|
7
8
|
|
|
8
9
|
import { toPascalCase } from "../utils/convertString";
|
|
10
|
+
import { isConstructOrStackType, isConstructType } from "../utils/typeCheck";
|
|
9
11
|
|
|
10
12
|
type Context = TSESLint.RuleContext<"noParentNameConstructIdMatch", []>;
|
|
11
13
|
|
|
@@ -14,6 +16,7 @@ type ValidateStatementArgs<T extends TSESTree.Statement> = {
|
|
|
14
16
|
statement: T;
|
|
15
17
|
parentClassName: string;
|
|
16
18
|
context: Context;
|
|
19
|
+
parserServices: ParserServicesWithTypeInformation;
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
type ValidateExpressionArgs<T extends TSESTree.Expression> = {
|
|
@@ -21,6 +24,7 @@ type ValidateExpressionArgs<T extends TSESTree.Expression> = {
|
|
|
21
24
|
expression: T;
|
|
22
25
|
parentClassName: string;
|
|
23
26
|
context: Context;
|
|
27
|
+
parserServices: ParserServicesWithTypeInformation;
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
/**
|
|
@@ -45,8 +49,13 @@ export const noParentNameConstructIdMatch = ESLintUtils.RuleCreator.withoutDocs(
|
|
|
45
49
|
},
|
|
46
50
|
defaultOptions: [],
|
|
47
51
|
create(context) {
|
|
52
|
+
const parserServices = ESLintUtils.getParserServices(context);
|
|
48
53
|
return {
|
|
49
54
|
ClassBody(node) {
|
|
55
|
+
const type = parserServices.getTypeAtLocation(node);
|
|
56
|
+
|
|
57
|
+
if (!isConstructOrStackType(type)) return;
|
|
58
|
+
|
|
50
59
|
const parent = node.parent;
|
|
51
60
|
if (parent?.type !== AST_NODE_TYPES.ClassDeclaration) return;
|
|
52
61
|
|
|
@@ -67,6 +76,7 @@ export const noParentNameConstructIdMatch = ESLintUtils.RuleCreator.withoutDocs(
|
|
|
67
76
|
expression: body.value,
|
|
68
77
|
parentClassName,
|
|
69
78
|
context,
|
|
79
|
+
parserServices,
|
|
70
80
|
});
|
|
71
81
|
}
|
|
72
82
|
},
|
|
@@ -84,6 +94,7 @@ const validateConstructorBody = ({
|
|
|
84
94
|
expression,
|
|
85
95
|
parentClassName,
|
|
86
96
|
context,
|
|
97
|
+
parserServices,
|
|
87
98
|
}: ValidateExpressionArgs<TSESTree.FunctionExpression>): void => {
|
|
88
99
|
for (const statement of expression.body.body) {
|
|
89
100
|
switch (statement.type) {
|
|
@@ -95,6 +106,7 @@ const validateConstructorBody = ({
|
|
|
95
106
|
context,
|
|
96
107
|
expression: newExpression,
|
|
97
108
|
parentClassName,
|
|
109
|
+
parserServices,
|
|
98
110
|
});
|
|
99
111
|
break;
|
|
100
112
|
}
|
|
@@ -105,6 +117,7 @@ const validateConstructorBody = ({
|
|
|
105
117
|
statement,
|
|
106
118
|
parentClassName,
|
|
107
119
|
context,
|
|
120
|
+
parserServices,
|
|
108
121
|
});
|
|
109
122
|
break;
|
|
110
123
|
}
|
|
@@ -114,6 +127,7 @@ const validateConstructorBody = ({
|
|
|
114
127
|
context,
|
|
115
128
|
parentClassName,
|
|
116
129
|
statement: statement.consequent,
|
|
130
|
+
parserServices,
|
|
117
131
|
});
|
|
118
132
|
break;
|
|
119
133
|
}
|
|
@@ -125,6 +139,7 @@ const validateConstructorBody = ({
|
|
|
125
139
|
context,
|
|
126
140
|
parentClassName,
|
|
127
141
|
statement,
|
|
142
|
+
parserServices,
|
|
128
143
|
});
|
|
129
144
|
}
|
|
130
145
|
}
|
|
@@ -144,6 +159,7 @@ const traverseStatements = ({
|
|
|
144
159
|
statement,
|
|
145
160
|
parentClassName,
|
|
146
161
|
context,
|
|
162
|
+
parserServices,
|
|
147
163
|
}: ValidateStatementArgs<TSESTree.Statement>) => {
|
|
148
164
|
switch (statement.type) {
|
|
149
165
|
case AST_NODE_TYPES.BlockStatement: {
|
|
@@ -153,6 +169,7 @@ const traverseStatements = ({
|
|
|
153
169
|
statement: body,
|
|
154
170
|
parentClassName,
|
|
155
171
|
context,
|
|
172
|
+
parserServices,
|
|
156
173
|
});
|
|
157
174
|
}
|
|
158
175
|
break;
|
|
@@ -165,6 +182,7 @@ const traverseStatements = ({
|
|
|
165
182
|
statement,
|
|
166
183
|
parentClassName,
|
|
167
184
|
context,
|
|
185
|
+
parserServices,
|
|
168
186
|
});
|
|
169
187
|
break;
|
|
170
188
|
}
|
|
@@ -176,6 +194,7 @@ const traverseStatements = ({
|
|
|
176
194
|
context,
|
|
177
195
|
expression: newExpression,
|
|
178
196
|
parentClassName,
|
|
197
|
+
parserServices,
|
|
179
198
|
});
|
|
180
199
|
break;
|
|
181
200
|
}
|
|
@@ -192,6 +211,7 @@ const validateStatement = ({
|
|
|
192
211
|
statement,
|
|
193
212
|
parentClassName,
|
|
194
213
|
context,
|
|
214
|
+
parserServices,
|
|
195
215
|
}: ValidateStatementArgs<TSESTree.Statement>): void => {
|
|
196
216
|
switch (statement.type) {
|
|
197
217
|
case AST_NODE_TYPES.VariableDeclaration: {
|
|
@@ -202,6 +222,7 @@ const validateStatement = ({
|
|
|
202
222
|
context,
|
|
203
223
|
expression: newExpression,
|
|
204
224
|
parentClassName,
|
|
225
|
+
parserServices,
|
|
205
226
|
});
|
|
206
227
|
break;
|
|
207
228
|
}
|
|
@@ -213,6 +234,7 @@ const validateStatement = ({
|
|
|
213
234
|
context,
|
|
214
235
|
expression: newExpression,
|
|
215
236
|
parentClassName,
|
|
237
|
+
parserServices,
|
|
216
238
|
});
|
|
217
239
|
break;
|
|
218
240
|
}
|
|
@@ -222,6 +244,7 @@ const validateStatement = ({
|
|
|
222
244
|
statement,
|
|
223
245
|
parentClassName,
|
|
224
246
|
context,
|
|
247
|
+
parserServices,
|
|
225
248
|
});
|
|
226
249
|
break;
|
|
227
250
|
}
|
|
@@ -231,6 +254,7 @@ const validateStatement = ({
|
|
|
231
254
|
statement,
|
|
232
255
|
parentClassName,
|
|
233
256
|
context,
|
|
257
|
+
parserServices,
|
|
234
258
|
});
|
|
235
259
|
break;
|
|
236
260
|
}
|
|
@@ -246,12 +270,14 @@ const validateIfStatement = ({
|
|
|
246
270
|
statement,
|
|
247
271
|
parentClassName,
|
|
248
272
|
context,
|
|
273
|
+
parserServices,
|
|
249
274
|
}: ValidateStatementArgs<TSESTree.IfStatement>): void => {
|
|
250
275
|
traverseStatements({
|
|
251
276
|
node,
|
|
252
277
|
context,
|
|
253
278
|
parentClassName,
|
|
254
279
|
statement: statement.consequent,
|
|
280
|
+
parserServices,
|
|
255
281
|
});
|
|
256
282
|
};
|
|
257
283
|
|
|
@@ -264,6 +290,7 @@ const validateSwitchStatement = ({
|
|
|
264
290
|
statement,
|
|
265
291
|
parentClassName,
|
|
266
292
|
context,
|
|
293
|
+
parserServices,
|
|
267
294
|
}: ValidateStatementArgs<TSESTree.SwitchStatement>): void => {
|
|
268
295
|
for (const caseStatement of statement.cases) {
|
|
269
296
|
for (const _consequent of caseStatement.consequent) {
|
|
@@ -272,6 +299,7 @@ const validateSwitchStatement = ({
|
|
|
272
299
|
context,
|
|
273
300
|
parentClassName,
|
|
274
301
|
statement: _consequent,
|
|
302
|
+
parserServices,
|
|
275
303
|
});
|
|
276
304
|
}
|
|
277
305
|
}
|
|
@@ -285,7 +313,10 @@ const validateConstructId = ({
|
|
|
285
313
|
context,
|
|
286
314
|
expression,
|
|
287
315
|
parentClassName,
|
|
316
|
+
parserServices,
|
|
288
317
|
}: ValidateExpressionArgs<TSESTree.NewExpression>): void => {
|
|
318
|
+
const type = parserServices.getTypeAtLocation(expression);
|
|
319
|
+
|
|
289
320
|
if (expression.arguments.length < 2) return;
|
|
290
321
|
|
|
291
322
|
// NOTE: Treat the second argument as ID
|
|
@@ -299,14 +330,17 @@ const validateConstructId = ({
|
|
|
299
330
|
|
|
300
331
|
const formattedConstructId = toPascalCase(secondArg.value);
|
|
301
332
|
const formattedParentClassName = toPascalCase(parentClassName);
|
|
302
|
-
if (formattedParentClassName !== formattedConstructId) return;
|
|
303
333
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
334
|
+
if (!isConstructType(type)) return;
|
|
335
|
+
|
|
336
|
+
if (formattedConstructId.includes(formattedParentClassName)) {
|
|
337
|
+
context.report({
|
|
338
|
+
node,
|
|
339
|
+
messageId: "noParentNameConstructIdMatch",
|
|
340
|
+
data: {
|
|
341
|
+
constructId: secondArg.value,
|
|
342
|
+
parentConstructName: parentClassName,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
}
|
|
312
346
|
};
|