eslint-cdk-plugin 3.0.0 → 3.0.3
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 +119 -96
- package/dist/index.mjs +119 -96
- package/package.json +3 -2
- package/src/rules/construct-constructor-property.ts +34 -36
- package/src/rules/no-construct-in-interface.ts +10 -2
- package/src/rules/no-construct-in-public-property-of-construct.ts +59 -49
- package/src/rules/no-construct-stack-suffix.ts +3 -2
- package/src/rules/no-import-private.ts +1 -1
- package/src/rules/no-mutable-property-of-props-interface.ts +49 -49
- package/src/rules/no-mutable-public-property-of-construct.ts +60 -60
- package/src/rules/no-parent-name-construct-id-match.ts +60 -61
- package/src/rules/no-variable-construct-id.ts +3 -1
- package/src/rules/pascal-case-construct-id.ts +3 -2
- package/src/rules/props-name-convention.ts +3 -2
- package/src/rules/require-jsdoc.ts +3 -2
- package/src/rules/require-passing-this.ts +3 -2
- package/src/rules/require-props-default-doc.ts +5 -7
- package/src/utils/createRule.ts +5 -0
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,11 @@ 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 = "3.0.3";
|
|
30
|
+
|
|
31
|
+
const createRule = utils.ESLintUtils.RuleCreator(
|
|
32
|
+
(name) => `https://eslint-cdk-plugin.dev/rules/${name}`
|
|
33
|
+
);
|
|
30
34
|
|
|
31
35
|
const isConstructOrStackType = (type, ignoredClasses = ["App", "Stage"]) => {
|
|
32
36
|
if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
|
|
@@ -49,35 +53,34 @@ const isTargetSuperClassType = (type, targetSuperClasses, typeCheckFunction) =>
|
|
|
49
53
|
return baseTypes.some((baseType) => typeCheckFunction(baseType));
|
|
50
54
|
};
|
|
51
55
|
|
|
52
|
-
const constructConstructorProperty =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
messages: {
|
|
60
|
-
invalidConstructorProperty: "Constructor of a class extending Construct must have the property names 'scope, id' or 'scope, id, props'"
|
|
61
|
-
},
|
|
62
|
-
schema: []
|
|
56
|
+
const constructConstructorProperty = createRule({
|
|
57
|
+
name: "construct-constructor-property",
|
|
58
|
+
meta: {
|
|
59
|
+
type: "problem",
|
|
60
|
+
docs: {
|
|
61
|
+
description: "Enforces that constructors of classes extending Construct have the property names 'scope, id' or 'scope, id, props'"
|
|
63
62
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
messages: {
|
|
64
|
+
invalidConstructorProperty: "Constructor of a class extending Construct must have the property names 'scope, id' or 'scope, id, props'"
|
|
65
|
+
},
|
|
66
|
+
schema: []
|
|
67
|
+
},
|
|
68
|
+
defaultOptions: [],
|
|
69
|
+
create(context) {
|
|
70
|
+
const parserServices = utils.ESLintUtils.getParserServices(context);
|
|
71
|
+
return {
|
|
72
|
+
ClassDeclaration(node) {
|
|
73
|
+
const type = parserServices.getTypeAtLocation(node);
|
|
74
|
+
if (!isConstructType(type)) return;
|
|
75
|
+
const constructor = node.body.body.find(
|
|
76
|
+
(member) => member.type === utils.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
77
|
+
);
|
|
78
|
+
if (!constructor) return;
|
|
79
|
+
validateConstructorProperty(constructor, context);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
79
82
|
}
|
|
80
|
-
);
|
|
83
|
+
});
|
|
81
84
|
const validateConstructorProperty = (constructor, context) => {
|
|
82
85
|
const params = constructor.value.params;
|
|
83
86
|
if (params.length < 2) {
|
|
@@ -114,7 +117,16 @@ const validateConstructorProperty = (constructor, context) => {
|
|
|
114
117
|
}
|
|
115
118
|
};
|
|
116
119
|
|
|
117
|
-
const
|
|
120
|
+
const SYMBOL_FLAGS = {
|
|
121
|
+
CLASS: 32
|
|
122
|
+
};
|
|
123
|
+
const SYNTAX_KIND = {
|
|
124
|
+
CLASS_DECLARATION: 263,
|
|
125
|
+
CONSTRUCTOR: 176
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const noConstructInInterface = createRule({
|
|
129
|
+
name: "no-construct-in-interface",
|
|
118
130
|
meta: {
|
|
119
131
|
type: "problem",
|
|
120
132
|
docs: {
|
|
@@ -136,6 +148,8 @@ const noConstructInInterface = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
136
148
|
}
|
|
137
149
|
const type = parserServices.getTypeAtLocation(property);
|
|
138
150
|
if (!isConstructOrStackType(type)) continue;
|
|
151
|
+
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
|
|
152
|
+
if (!isClass) continue;
|
|
139
153
|
context.report({
|
|
140
154
|
node: property,
|
|
141
155
|
messageId: "invalidInterfaceProperty",
|
|
@@ -150,7 +164,8 @@ const noConstructInInterface = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
150
164
|
}
|
|
151
165
|
});
|
|
152
166
|
|
|
153
|
-
const noConstructInPublicPropertyOfConstruct =
|
|
167
|
+
const noConstructInPublicPropertyOfConstruct = createRule({
|
|
168
|
+
name: "no-construct-in-public-property-of-construct",
|
|
154
169
|
meta: {
|
|
155
170
|
type: "problem",
|
|
156
171
|
docs: {
|
|
@@ -195,6 +210,8 @@ const validatePublicPropertyOfConstruct = (node, context, parserServices) => {
|
|
|
195
210
|
if (!property.typeAnnotation) continue;
|
|
196
211
|
const type = parserServices.getTypeAtLocation(property);
|
|
197
212
|
if (!isConstructOrStackType(type)) continue;
|
|
213
|
+
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
|
|
214
|
+
if (!isClass) continue;
|
|
198
215
|
context.report({
|
|
199
216
|
node: property,
|
|
200
217
|
messageId: "invalidPublicPropertyOfConstruct",
|
|
@@ -216,6 +233,8 @@ const validateConstructorParameterProperty = (constructor, context, parserServic
|
|
|
216
233
|
if (!param.parameter.typeAnnotation) continue;
|
|
217
234
|
const type = parserServices.getTypeAtLocation(param);
|
|
218
235
|
if (!isConstructOrStackType(type)) continue;
|
|
236
|
+
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
|
|
237
|
+
if (!isClass) continue;
|
|
219
238
|
context.report({
|
|
220
239
|
node: param,
|
|
221
240
|
messageId: "invalidPublicPropertyOfConstruct",
|
|
@@ -235,11 +254,6 @@ const toPascalCase = (str) => {
|
|
|
235
254
|
}).join("");
|
|
236
255
|
};
|
|
237
256
|
|
|
238
|
-
const SYNTAX_KIND = {
|
|
239
|
-
CLASS_DECLARATION: 263,
|
|
240
|
-
CONSTRUCTOR: 176
|
|
241
|
-
};
|
|
242
|
-
|
|
243
257
|
const getConstructorPropertyNames = (type) => {
|
|
244
258
|
const declarations = type.symbol?.declarations;
|
|
245
259
|
if (!declarations?.length) return [];
|
|
@@ -262,7 +276,8 @@ const SUFFIX_TYPE = {
|
|
|
262
276
|
CONSTRUCT: "Construct",
|
|
263
277
|
STACK: "Stack"
|
|
264
278
|
};
|
|
265
|
-
const noConstructStackSuffix =
|
|
279
|
+
const noConstructStackSuffix = createRule({
|
|
280
|
+
name: "no-construct-stack-suffix",
|
|
266
281
|
meta: {
|
|
267
282
|
type: "problem",
|
|
268
283
|
docs: {
|
|
@@ -345,6 +360,7 @@ const noImportPrivate = {
|
|
|
345
360
|
meta: {
|
|
346
361
|
type: "problem",
|
|
347
362
|
docs: {
|
|
363
|
+
url: "https://eslint-cdk-plugin.dev/rules/no-import-private",
|
|
348
364
|
description: "Cannot import modules from private dir at different levels of the hierarchy."
|
|
349
365
|
},
|
|
350
366
|
messages: {
|
|
@@ -377,7 +393,8 @@ const getDirSegments = (dirPath) => {
|
|
|
377
393
|
return dirPath.split(path__namespace.sep).filter((segment) => segment !== "");
|
|
378
394
|
};
|
|
379
395
|
|
|
380
|
-
const noMutablePropertyOfPropsInterface =
|
|
396
|
+
const noMutablePropertyOfPropsInterface = createRule({
|
|
397
|
+
name: "no-mutable-property-of-props-interface",
|
|
381
398
|
meta: {
|
|
382
399
|
type: "problem",
|
|
383
400
|
docs: {
|
|
@@ -417,7 +434,8 @@ const noMutablePropertyOfPropsInterface = utils.ESLintUtils.RuleCreator.withoutD
|
|
|
417
434
|
}
|
|
418
435
|
});
|
|
419
436
|
|
|
420
|
-
const noMutablePublicPropertyOfConstruct =
|
|
437
|
+
const noMutablePublicPropertyOfConstruct = createRule({
|
|
438
|
+
name: "no-mutable-public-property-of-construct",
|
|
421
439
|
meta: {
|
|
422
440
|
type: "problem",
|
|
423
441
|
docs: {
|
|
@@ -468,64 +486,63 @@ const noMutablePublicPropertyOfConstruct = utils.ESLintUtils.RuleCreator.without
|
|
|
468
486
|
}
|
|
469
487
|
});
|
|
470
488
|
|
|
471
|
-
const noParentNameConstructIdMatch =
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
},
|
|
481
|
-
schema: [
|
|
482
|
-
{
|
|
483
|
-
type: "object",
|
|
484
|
-
properties: {
|
|
485
|
-
disallowContainingParentName: {
|
|
486
|
-
type: "boolean",
|
|
487
|
-
default: false
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
additionalProperties: false
|
|
491
|
-
}
|
|
492
|
-
]
|
|
489
|
+
const noParentNameConstructIdMatch = createRule({
|
|
490
|
+
name: "no-parent-name-construct-id-match",
|
|
491
|
+
meta: {
|
|
492
|
+
type: "problem",
|
|
493
|
+
docs: {
|
|
494
|
+
description: "Enforce that construct IDs does not match the parent construct name."
|
|
495
|
+
},
|
|
496
|
+
messages: {
|
|
497
|
+
invalidConstructId: "Construct ID '{{ constructId }}' should not match parent construct name '{{ parentConstructName }}'. Use a more specific identifier."
|
|
493
498
|
},
|
|
494
|
-
|
|
499
|
+
schema: [
|
|
495
500
|
{
|
|
496
|
-
|
|
501
|
+
type: "object",
|
|
502
|
+
properties: {
|
|
503
|
+
disallowContainingParentName: {
|
|
504
|
+
type: "boolean",
|
|
505
|
+
default: false
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
additionalProperties: false
|
|
497
509
|
}
|
|
498
|
-
]
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
option
|
|
522
|
-
});
|
|
510
|
+
]
|
|
511
|
+
},
|
|
512
|
+
defaultOptions: [
|
|
513
|
+
{
|
|
514
|
+
disallowContainingParentName: false
|
|
515
|
+
}
|
|
516
|
+
],
|
|
517
|
+
create(context) {
|
|
518
|
+
const option = context.options[0] || {
|
|
519
|
+
disallowContainingParentName: false
|
|
520
|
+
};
|
|
521
|
+
const parserServices = utils.ESLintUtils.getParserServices(context);
|
|
522
|
+
return {
|
|
523
|
+
ClassBody(node) {
|
|
524
|
+
const type = parserServices.getTypeAtLocation(node);
|
|
525
|
+
if (!isConstructOrStackType(type)) return;
|
|
526
|
+
const parent = node.parent;
|
|
527
|
+
if (parent?.type !== utils.AST_NODE_TYPES.ClassDeclaration) return;
|
|
528
|
+
const parentClassName = parent.id?.name;
|
|
529
|
+
if (!parentClassName) return;
|
|
530
|
+
for (const body of node.body) {
|
|
531
|
+
if (body.type !== utils.AST_NODE_TYPES.MethodDefinition || !["method", "constructor"].includes(body.kind) || body.value.type !== utils.AST_NODE_TYPES.FunctionExpression) {
|
|
532
|
+
continue;
|
|
523
533
|
}
|
|
534
|
+
validateConstructorBody({
|
|
535
|
+
expression: body.value,
|
|
536
|
+
parentClassName,
|
|
537
|
+
context,
|
|
538
|
+
parserServices,
|
|
539
|
+
option
|
|
540
|
+
});
|
|
524
541
|
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
527
544
|
}
|
|
528
|
-
);
|
|
545
|
+
});
|
|
529
546
|
const validateConstructorBody = ({
|
|
530
547
|
expression,
|
|
531
548
|
parentClassName,
|
|
@@ -758,7 +775,8 @@ const validateConstructId$2 = ({
|
|
|
758
775
|
}
|
|
759
776
|
};
|
|
760
777
|
|
|
761
|
-
const noVariableConstructId =
|
|
778
|
+
const noVariableConstructId = createRule({
|
|
779
|
+
name: "no-variable-construct-id",
|
|
762
780
|
meta: {
|
|
763
781
|
type: "problem",
|
|
764
782
|
docs: {
|
|
@@ -823,7 +841,8 @@ const QUOTE_TYPE = {
|
|
|
823
841
|
SINGLE: "'",
|
|
824
842
|
DOUBLE: '"'
|
|
825
843
|
};
|
|
826
|
-
const pascalCaseConstructId =
|
|
844
|
+
const pascalCaseConstructId = createRule({
|
|
845
|
+
name: "pascal-case-construct-id",
|
|
827
846
|
meta: {
|
|
828
847
|
type: "problem",
|
|
829
848
|
docs: {
|
|
@@ -872,7 +891,8 @@ const validateConstructId = (node, context) => {
|
|
|
872
891
|
});
|
|
873
892
|
};
|
|
874
893
|
|
|
875
|
-
const propsNameConvention =
|
|
894
|
+
const propsNameConvention = createRule({
|
|
895
|
+
name: "props-name-convention",
|
|
876
896
|
meta: {
|
|
877
897
|
type: "problem",
|
|
878
898
|
docs: {
|
|
@@ -919,7 +939,8 @@ const propsNameConvention = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
919
939
|
}
|
|
920
940
|
});
|
|
921
941
|
|
|
922
|
-
const requireJSDoc =
|
|
942
|
+
const requireJSDoc = createRule({
|
|
943
|
+
name: "require-jsdoc",
|
|
923
944
|
meta: {
|
|
924
945
|
type: "problem",
|
|
925
946
|
docs: {
|
|
@@ -984,7 +1005,8 @@ const requireJSDoc = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
984
1005
|
}
|
|
985
1006
|
});
|
|
986
1007
|
|
|
987
|
-
const requirePassingThis =
|
|
1008
|
+
const requirePassingThis = createRule({
|
|
1009
|
+
name: "require-passing-this",
|
|
988
1010
|
meta: {
|
|
989
1011
|
type: "problem",
|
|
990
1012
|
docs: {
|
|
@@ -1049,7 +1071,8 @@ const requirePassingThis = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
1049
1071
|
}
|
|
1050
1072
|
});
|
|
1051
1073
|
|
|
1052
|
-
const requirePropsDefaultDoc =
|
|
1074
|
+
const requirePropsDefaultDoc = createRule({
|
|
1075
|
+
name: "require-props-default-doc",
|
|
1053
1076
|
meta: {
|
|
1054
1077
|
type: "problem",
|
|
1055
1078
|
docs: {
|