Skip to content

chore(assertions): remove unnecessary condition for if statement in Template#32028

Merged
mergify[bot] merged 5 commits intoaws:mainfrom
go-to-k:chore-assertion-if
Nov 5, 2024
Merged

chore(assertions): remove unnecessary condition for if statement in Template#32028
mergify[bot] merged 5 commits intoaws:mainfrom
go-to-k:chore-assertion-if

Conversation

@go-to-k
Copy link
Copy Markdown
Contributor

@go-to-k go-to-k commented Nov 5, 2024

Reason for this change

The following is the code in the Template constructor in the assertions module:

    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

-    if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) {
+    if (!templateParsingOptions.skipCyclicalDependenciesCheck) {
      checkTemplateForCyclicDependencies(this.template);
    }

Description of how you validated changes

A unit test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team November 5, 2024 15:47
@github-actions github-actions bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Nov 5, 2024
@go-to-k go-to-k changed the title chore(assertions): remove unnecessary condition in if statement chore(assertions): remove unnecessary condition for Template in if statement Nov 5, 2024
@go-to-k go-to-k changed the title chore(assertions): remove unnecessary condition for Template in if statement chore(assertions): remove unnecessary condition in if statement for Template Nov 5, 2024
@go-to-k go-to-k changed the title chore(assertions): remove unnecessary condition in if statement for Template chore(assertions): remove unnecessary condition for if statement in Template Nov 5, 2024
});

test('does not throw when given a template with cyclic dependencies if check is skipped', () => {
test('throws when given a template with cyclic dependencies if skipCyclicalDependenciesCheck is false', () => {
Copy link
Copy Markdown
Contributor Author

@go-to-k go-to-k Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests for the undefined case already exists above this test.

In the case of true, not.toThrow is used, so I didn't summarize with test.each.

private constructor(template: { [key: string]: any }, templateParsingOptions: TemplateParsingOptions = {}) {
this.template = template as TemplateType;
if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) {
if (!templateParsingOptions.skipCyclicalDependenciesCheck) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a comment to confirm that skipCyclicalDependenciesCheck is meant to default to false, as is the behavior here.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: f65e782
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Nov 5, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 9027cd2 into aws:main Nov 5, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 5, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2024
@go-to-k go-to-k deleted the chore-assertion-if branch November 6, 2024 04:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants