From 8e3c4cabb4d11134ae6a289855bad32a0412efe1 Mon Sep 17 00:00:00 2001 From: shivlaks <32604953+shivlaks@users.noreply.github.com> Date: Mon, 13 May 2019 23:13:54 -0700 Subject: [PATCH] refactor: L2 constructs should use strong types instead of attributes. props should not have "arn" suffix (awslint:props-no-arn-refs) (#2539) * refactor: L2 constructs should use strong types instead of attributes. props should not have "arn" suffix (awslint:props-no-arn-refs) Adds a new awslint:props-no-arn-refs rule which valides that props do not have an "arn" suffix. Props should use strong types instead of attributes. This is in accordance with the new AWS Construct Library guidelines. Fixes #2436 * excluding CrossAccountDestination construct which supports CloudWatchLogs to Kinesis streams in a different destination account --- packages/@aws-cdk/aws-logs/package.json | 5 +++++ tools/awslint/lib/rules/construct.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/@aws-cdk/aws-logs/package.json b/packages/@aws-cdk/aws-logs/package.json index 3b756b35832f6..43da43dca4c5e 100644 --- a/packages/@aws-cdk/aws-logs/package.json +++ b/packages/@aws-cdk/aws-logs/package.json @@ -77,5 +77,10 @@ }, "engines": { "node": ">= 8.10.0" + }, + "awslint": { + "exclude": [ + "props-no-arn-refs:@aws-cdk/aws-logs.CrossAccountDestinationProps.targetArn" + ] } } diff --git a/tools/awslint/lib/rules/construct.ts b/tools/awslint/lib/rules/construct.ts index d1b50276dde9c..de6926a0bd53e 100644 --- a/tools/awslint/lib/rules/construct.ts +++ b/tools/awslint/lib/rules/construct.ts @@ -211,4 +211,20 @@ constructLinter.add({ e.assert(!property.type.unionOfTypes, `${e.ctx.propsFqn}.${property.name}`); } } +}); + +constructLinter.add({ + code: 'props-no-arn-refs', + message: 'props should use strong types instead of attributes. props should not have "arn" suffix', + eval: e => { + if (!e.ctx.propsType) { return; } + if (!e.ctx.hasPropsArgument) { return; } + + // this rule only applies to L2 constructs + if (e.ctx.classType.name.startsWith('Cfn')) { return; } + + for (const property of e.ctx.propsType.ownProperties) { + e.assert(!property.name.toLowerCase().endsWith('arn'), `${e.ctx.propsFqn}.${property.name}`); + } + } }); \ No newline at end of file