Skip to content

Commit cb2b334

Browse files
authored
refactor: Construct props must not use the 'any' type (awslint:props-no-any) (#2701)
Adds a new awslint:props-no-any rule which validates that props do not use the "any" type. This is in accordance with the new AWS Construct Library guidelines. BREAKING CHANGE: * SNS - Subscription `endpoint` is now type `string` (previously `any`) * Step Functions - `result` in the Pass state is now type `map` (previously `any`) **Fixes #2673**
1 parent 08a2852 commit cb2b334

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

packages/@aws-cdk/aws-sns/lib/subscription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface SubscriptionProps {
1616
*
1717
* The meaning of this value depends on the value for 'protocol'.
1818
*/
19-
readonly endpoint: any;
19+
readonly endpoint: string;
2020

2121
/**
2222
* The topic to subscribe to.

packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface PassProps {
5151
*
5252
* @default No injected result
5353
*/
54-
readonly result?: any;
54+
readonly result?: {[key: string]: any};
5555
}
5656

5757
/**

packages/@aws-cdk/cdk/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"construct-ctor:@aws-cdk/cdk.App.<initializer>",
3737
"construct-ctor:@aws-cdk/cdk.Root.<initializer>",
3838
"construct-ctor:@aws-cdk/cdk.Stack.<initializer>.params*",
39+
"props-no-any:@aws-cdk/cdk.CfnOutputProps.value",
40+
"props-no-any:@aws-cdk/cdk.CfnParameterProps.default",
41+
"props-no-any:@aws-cdk/cdk.CfnResourceProps.properties",
3942
"props-no-cfn-types:@aws-cdk/cdk.CfnOutputProps*",
4043
"props-no-cfn-types:@aws-cdk/cdk.StringListCfnOutputProps*"
4144
]

packages/@aws-cdk/runtime-values/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,10 @@
7676
},
7777
"engines": {
7878
"node": ">= 8.10.0"
79+
},
80+
"awslint": {
81+
"exclude": [
82+
"props-no-any:@aws-cdk/runtime-values.RuntimeValueProps.value"
83+
]
7984
}
8085
}

tools/awslint/lib/rules/construct.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ constructLinter.add({
189189

190190
constructLinter.add({
191191
code: 'props-no-unions',
192-
message: 'props should not use TypeScript unions',
192+
message: 'props must not use TypeScript unions',
193193
eval: e => {
194194
if (!e.ctx.propsType) { return; }
195195
if (!e.ctx.hasPropsArgument) { return; }
196196

197-
// this rule only applies to L2 constructs
197+
// this rule does not apply to L1 constructs
198198
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
199199

200200
for (const property of e.ctx.propsType.ownProperties) {
@@ -205,12 +205,12 @@ constructLinter.add({
205205

206206
constructLinter.add({
207207
code: 'props-no-arn-refs',
208-
message: 'props should use strong types instead of attributes. props should not have "arn" suffix',
208+
message: 'props must use strong types instead of attributes. props should not have "arn" suffix',
209209
eval: e => {
210210
if (!e.ctx.propsType) { return; }
211211
if (!e.ctx.hasPropsArgument) { return; }
212212

213-
// this rule only applies to L2 constructs
213+
// this rule does not apply to L1 constructs
214214
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
215215

216216
for (const property of e.ctx.propsType.ownProperties) {
@@ -221,12 +221,12 @@ constructLinter.add({
221221

222222
constructLinter.add({
223223
code: 'props-no-tokens',
224-
message: 'props should not use the "Token" type',
224+
message: 'props must not use the "Token" type',
225225
eval: e => {
226226
if (!e.ctx.propsType) { return; }
227227
if (!e.ctx.hasPropsArgument) { return; }
228228

229-
// this rule only applies to L2 constructs
229+
// this rule does not apply to L1 constructs
230230
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
231231

232232
for (const property of e.ctx.propsType.allProperties) {
@@ -242,12 +242,12 @@ constructLinter.add({
242242

243243
constructLinter.add({
244244
code: 'props-no-cfn-types',
245-
message: 'props should not expose L1 types (types which start with "Cfn")',
245+
message: 'props must not expose L1 types (types which start with "Cfn")',
246246
eval: e => {
247247
if (!e.ctx.propsType) { return; }
248248
if (!e.ctx.hasPropsArgument) { return; }
249249

250-
// this rule only applies to L2 constructs
250+
// this rule does not apply to L1 constructs
251251
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
252252

253253
for (const property of e.ctx.propsType.ownProperties) {
@@ -263,17 +263,33 @@ constructLinter.add({
263263

264264
constructLinter.add({
265265
code: 'props-default-doc',
266-
message: 'All optional props should have @default documentation',
266+
message: 'All optional props must have @default documentation',
267267
eval: e => {
268268
if (!e.ctx.propsType) { return; }
269269
if (!e.ctx.hasPropsArgument) { return; }
270270

271-
// this rule only applies to L2 constructs
271+
// this rule does not apply to L1 constructs
272272
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
273273

274274
for (const property of e.ctx.propsType.allProperties) {
275275
if (!property.optional) { continue; }
276276
e.assert(property.docs.docs.default !== undefined, `${e.ctx.propsFqn}.${property.name}`);
277277
}
278278
}
279-
});
279+
});
280+
281+
constructLinter.add({
282+
code: 'props-no-any',
283+
message: 'props must not use Typescript "any" type',
284+
eval: e => {
285+
if (!e.ctx.propsType) { return; }
286+
if (!e.ctx.hasPropsArgument) { return; }
287+
288+
// this rule does not apply to L1 constructs
289+
if (CoreTypes.isCfnResource(e.ctx.classType)) { return; }
290+
291+
for (const property of e.ctx.propsType.ownProperties) {
292+
e.assert(!property.type.isAny, `${e.ctx.propsFqn}.${property.name}`);
293+
}
294+
}
295+
});

0 commit comments

Comments
 (0)