Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: L2 constructs should not use TypeScript unions (awslint:props-no-unions) (#2430) #2509

Merged
merged 2 commits into from
May 13, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tools/awslint/lib/rules/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 @@ -193,4 +193,20 @@ constructLinter.add({
const baseFqn = `${e.ctx.classType.fqn}Base`;
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}`);
}
}
});