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

bug: enum validation picks odd convention for members with digits #3208

Closed
4 of 5 tasks
njlynch opened this issue Nov 26, 2021 · 1 comment · Fixed by #3209
Closed
4 of 5 tasks

bug: enum validation picks odd convention for members with digits #3208

njlynch opened this issue Nov 26, 2021 · 1 comment · Fixed by #3209
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@njlynch
Copy link
Contributor

njlynch commented Nov 26, 2021

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

General Information

  • JSII Version: (Not yet released as of this writing)
  • Platform: N/A

What is the problem?

jsii enforces a kind of odd convention for enum names, and the error message does not reflect the actual validation. See the below:

error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C5A" to "C5_A"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C5AD" to "C5_A_D"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C5D" to "C5_D"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C5N" to "C5_N"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C6G" to "C6_G"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C6GD" to "C6_G_D"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C6GN" to "C6_G_N"
error JSII8001: Enum members must be ALL_CAPS. Rename "aws-cdk-lib.aws_ec2.InstanceClass.C6I" to "C6_I"

It looks like

if (member.name && member.name !== Case.constant(member.name)) {
is the culprit. Our use of Case.constant() wants to introduce these underscores.

The above are live values in the aws-cdk, but they haven't been a problem to date because of #2782. However, I just tested the fix (#3207), and the CDK build fails due to the above. Given that our JS/TS users are able to use the values (e.g., C5A), we can't rename them, as it would be a breaking change. Instead, I propose we update the validation to support this case (likely replacing Case.constant with our own code and/or something else).

@njlynch njlynch added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 26, 2021
rix0rrr added a commit that referenced this issue Nov 26, 2021
An enum identifier like `C5A` is not possible: the `case` library we use
to assert casing will insist you change it to `C5_A`.

Bypass this rule for constant-like values: do a more lenient validation
of our own.

Fixes #3208.
@mergify mergify bot closed this as completed in #3209 Nov 26, 2021
mergify bot pushed a commit that referenced this issue Nov 26, 2021
An enum identifier like `C5A` is not possible: the `case` library we use
to assert casing will insist you change it to `C5_A`.

Bypass this rule for constant-like values: do a more lenient validation
of our own.

Fixes #3208.



---

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

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant