Skip to content

chore(cli): cli import code never reaches "??" operator#28113

Merged
mergify[bot] merged 3 commits intomainfrom
conroy/import
Nov 23, 2023
Merged

chore(cli): cli import code never reaches "??" operator#28113
mergify[bot] merged 3 commits intomainfrom
conroy/import

Conversation

@kaizencc
Copy link
Copy Markdown
Contributor

We're seeing this linter error flag: Warning: G] The "??" operator here will always return the left operand [suspicious-nullish-coalescing] in the yarn upgrade task.

It is because const defaultValue = typeof resourceProps[idProp] ?? ''; never reaches the ?? since typeof returns a string (returns "undefined" when the type its looking at is undefined). The code in question is buggy, but also ambiguous in meaning. It could mean:

const defaultValue = typeof (resourceProps[idProp] ?? '');, which means that we want defaultValue === 'string' when resourceProps[idProp] === undefined.

or

const defaultValue = resourceProps[idProp] ? typeof resourceProps[idProp] : '';, which means that we want defaultValue === '' when resourceProps[idProp] === undefined.

Later on we use defaultValue as the condition in a ternary operator. This tells me that the latter is the correct way to interpret the code's intention, since '' evaluates to false. All other options, including 'string' and 'undefined', evaluate to true.


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

@github-actions github-actions bot added the p2 label Nov 22, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 22, 2023 21:44
@kaizencc kaizencc added pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested and removed p2 labels Nov 22, 2023
@kaizencc kaizencc added the p2 label Nov 22, 2023
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 22, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 22, 2023
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Nov 23, 2023

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

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit 49839b2 into main Nov 23, 2023
@mergify mergify bot deleted the conroy/import branch November 23, 2023 14:50
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Nov 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants