Skip to content

Commit 9027cd2

Browse files
authored
chore(assertions): remove unnecessary condition for if statement in Template (#32028)
### Reason for this change The following is the code in the `Template` constructor in the assertions module: ```ts if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) { checkTemplateForCyclicDependencies(this.template); } ``` However, since the left operand (`!templateParsingOptions?.skipCyclicalDependenciesCheck`) is never undefined (null), the right operand (`?? true`) should not be needed. And the `templateParsingOptions` is not optional arg. ### Description of changes ```diff - if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) { + if (!templateParsingOptions.skipCyclicalDependenciesCheck) { checkTemplateForCyclicDependencies(this.template); } ``` ### Description of how you validated changes A unit test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2f9fb1e commit 9027cd2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/aws-cdk-lib/assertions/lib/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Template {
5454

5555
private constructor(template: { [key: string]: any }, templateParsingOptions: TemplateParsingOptions = {}) {
5656
this.template = template as TemplateType;
57-
if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) {
57+
if (!templateParsingOptions.skipCyclicalDependenciesCheck) {
5858
checkTemplateForCyclicDependencies(this.template);
5959
}
6060
}

packages/aws-cdk-lib/assertions/test/template.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,28 @@ describe('Template', () => {
13681368
}).toThrow(/dependency cycle/);
13691369
});
13701370

1371-
test('does not throw when given a template with cyclic dependencies if check is skipped', () => {
1371+
test('throws when given a template with cyclic dependencies if skipCyclicalDependenciesCheck is false', () => {
1372+
expect(() => {
1373+
Template.fromJSON({
1374+
Resources: {
1375+
Res1: {
1376+
Type: 'Foo',
1377+
Properties: {
1378+
Thing: { Ref: 'Res2' },
1379+
},
1380+
},
1381+
Res2: {
1382+
Type: 'Foo',
1383+
DependsOn: ['Res1'],
1384+
},
1385+
},
1386+
}, {
1387+
skipCyclicalDependenciesCheck: false,
1388+
});
1389+
}).toThrow(/dependency cycle/);
1390+
});
1391+
1392+
test('does not throw when given a template with cyclic dependencies if skipCyclicalDependenciesCheck is true', () => {
13721393
expect(() => {
13731394
Template.fromJSON({
13741395
Resources: {

0 commit comments

Comments
 (0)