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

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

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

go-to-k
Copy link
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
@@ -1368,7 +1368,28 @@ describe('Template', () => {
}).toThrow(/dependency cycle/);
});

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
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.

@@ -54,7 +54,7 @@ export class Template {

private constructor(template: { [key: string]: any }, templateParsingOptions: TemplateParsingOptions = {}) {
this.template = template as TemplateType;
if (!templateParsingOptions?.skipCyclicalDependenciesCheck ?? true) {
if (!templateParsingOptions.skipCyclicalDependenciesCheck) {
Copy link
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
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

Copy link
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
30 checks passed
Copy link

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