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)

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
  • Loading branch information
shivlaks committed May 13, 2019
1 parent 7863ad3 commit c4a1055
Showing 1 changed file with 16 additions and 0 deletions.
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 c4a1055

Please sign in to comment.