Skip to content

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

@njlynch

Description

@njlynch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions