Skip to content

Commit

Permalink
refactor: L2 constructs should use strong types instead of attributes…
Browse files Browse the repository at this point in the history
…. 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
  • Loading branch information
shivlaks authored May 14, 2019
1 parent b9eeaa0 commit 8e3c4ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@
},
"engines": {
"node": ">= 8.10.0"
},
"awslint": {
"exclude": [
"props-no-arn-refs:@aws-cdk/aws-logs.CrossAccountDestinationProps.targetArn"
]
}
}
16 changes: 16 additions & 0 deletions tools/awslint/lib/rules/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
});

0 comments on commit 8e3c4ca

Please sign in to comment.