Skip to content

Commit

Permalink
refactor: L2 constructs should not use TypeScript unions (awslint:pro…
Browse files Browse the repository at this point in the history
…ps-no-unions) (#2430) (#2509)

Adds a new awslint:props-no-unions rule which valides that props for L2 constructs do not use TypeScript unions. This is in accordance with the new AWS Construct Library guidelines.
  • Loading branch information
shivlaks authored May 13, 2019
1 parent 6fc3718 commit 7863ad3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/awslint/lib/rules/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class ConstructReflection {
}

if (!found.isInterfaceType()) {
throw new Error(`Expecrting props struct ${this.propsFqn} to be an interface`);
throw new Error(`Expecting props struct ${this.propsFqn} to be an interface`);
}

return found;
Expand Down Expand Up @@ -196,3 +196,19 @@ constructLinter.add({
e.assert(!e.ctx.sys.tryFindFqn(baseFqn), baseFqn);
}
});

constructLinter.add({
code: 'props-no-unions',
message: 'props should not use TypeScript unions',
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.type.unionOfTypes, `${e.ctx.propsFqn}.${property.name}`);
}
}
});

0 comments on commit 7863ad3

Please sign in to comment.