Skip to content

Commit

Permalink
fix(awslint): Don't fail if the @aws-cdk/cdk module is not present (#…
Browse files Browse the repository at this point in the history
…1953)

This simply means that no class may be a `Construct` or `Resource`, and
that is a pretty valid thing to have.
  • Loading branch information
RomainMuller authored Mar 5, 2019
1 parent 82d1862 commit 929e854
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tools/awslint/lib/cfn-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export function findCfnResources(assembly: reflect.Assembly): CfnResourceSpec[]
}

function isCfnResource(c: reflect.ClassType) {
const resourceBaseClass = c.system.findFqn('@aws-cdk/cdk.Resource');
const cdkAssembly = '@aws-cdk/cdk';
if (!c.system.includesAssembly(cdkAssembly)) {
return false;
}
const resourceBaseClass = c.system.findFqn(`${cdkAssembly}.Resource`);

if (!isConstruct(c)) {
return false;
Expand Down
8 changes: 6 additions & 2 deletions tools/awslint/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import reflect = require('jsii-reflect');

export const CONSTRUCT_FQN = '@aws-cdk/cdk.Construct';
export const CONSTRUCT_INTERFACE_FQN = '@aws-cdk/cdk.IConstruct';
export const CONSTRUCT_ASSEMBLY = '@aws-cdk/cdk';
export const CONSTRUCT_FQN = `${CONSTRUCT_ASSEMBLY}.Construct`;
export const CONSTRUCT_INTERFACE_FQN = `${CONSTRUCT_ASSEMBLY}.IConstruct`;

export function isConstruct(c: reflect.ClassType) {
if (!c.system.includesAssembly(CONSTRUCT_ASSEMBLY)) {
return false;
}
const constructClass = c.system.findFqn(CONSTRUCT_FQN);
const bases = c.getAncestors();
const root = bases[bases.length - 1];
Expand Down

0 comments on commit 929e854

Please sign in to comment.