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

feat(jsii): enforce enum names to be UPPER_CASE #541

Merged
merged 18 commits into from
Jun 20, 2019

Conversation

shivlaks
Copy link
Contributor

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

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

No..... enum member names, not type names :-(

@@ -63,13 +64,26 @@ function _defaultValidations(): ValidationFunction[] {

function _typeNamesMustUsePascalCase(_: Validator, assembly: spec.Assembly, diagnostic: DiagnosticEmitter) {
for (const type of _allTypes(assembly)) {
if (spec.isEnumType(type)) { continue; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The enum /type/ should be pascal case, just members should be capital

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah i see, totally misread that - so enum values then?
i'll get on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Enum members:

export enum MyEnum {
  MEMBER_NUMBER_ONE,
  MEMBER_FOO,
  MEMBER_XOO
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -1,4 +1,4 @@
///!MATCH_ERROR: Type names must use PascalCase: My_Enum
///!MATCH_ERROR: Enum names must use TRUMP_CASE: My_Enum
Copy link
Contributor

Choose a reason for hiding this comment

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

Nope! Just the member names should be TRUMP_CASE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think my Java disposition's are showing - enum names vs enum values. I'll get it updated!

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Need to make a decision about python and .NET. Not sure what's the idiomatic way to express enum members in those languages.

Assert.Equal(EnumFromScopedModule.Value1, obj.LoadFoo());
obj.SaveFoo(EnumFromScopedModule.Value2);
Assert.Equal(EnumFromScopedModule.Value2, obj.Foo);
Assert.Equal(EnumFromScopedModule.VALUE2, obj.Foo);
Copy link
Contributor

Choose a reason for hiding this comment

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

wait... what's the convention for .NET? Do we want .NET to also use all-caps?
Same question for Python.... @garnaat is it idiomatic to use all caps for enum values?

Copy link
Contributor

Choose a reason for hiding this comment

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

  • .NET seems to prefer PascalCase.
  • Python looks like ALL_CAPS are good.

So basically, the .NET code generator needs to covert the case for .NET.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good question. I thought we wanted to avoid dropping into the language specific mangling... let me check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Pascal casing for both names and values are the idiomatic thing for .NET

Copy link
Contributor

Choose a reason for hiding this comment

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

No. We wanted to normalize the typescript/jsii source to CAPITALS but then, jsii is all about language-specific idiomacy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll make the changes to the generation of .NET so we can change enum values into PascalCase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we decided we would make the changes for .NET generation to use enum members in PascalCase outside of this PR.

Should I create an issue for it before resolving this conversation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, "right click, create issue"

@shivlaks shivlaks marked this pull request as ready for review June 20, 2019 19:46
@shivlaks shivlaks requested review from costleya and a team as code owners June 20, 2019 19:46
packages/jsii/lib/validator.ts Outdated Show resolved Hide resolved
@shivlaks shivlaks merged commit c88080d into master Jun 20, 2019
@shivlaks shivlaks deleted the shivlaks/upper-case-all-enums branch June 28, 2019 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants