Skip to content

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

Merged
shivlaks merged 18 commits intomasterfrom
shivlaks/upper-case-all-enums
Jun 20, 2019
Merged

feat(jsii): enforce enum names to be UPPER_CASE#541
shivlaks merged 18 commits intomasterfrom
shivlaks/upper-case-all-enums

Conversation

@shivlaks
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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 :-(

Comment thread packages/jsii/lib/validator.ts Outdated

function _typeNamesMustUsePascalCase(_: Validator, assembly: spec.Assembly, diagnostic: DiagnosticEmitter) {
for (const type of _allTypes(assembly)) {
if (spec.isEnumType(type)) { continue; }
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 a team and costleya as code owners June 20, 2019 19:46
Comment thread packages/jsii/lib/validator.ts Outdated
@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