Skip to content

Commit c88080d

Browse files
authored
feat(jsii): enforce enum member names to be ALL_CAPS (#541)
Language generators will override as needed for language-specific idiomacy. BREAKING CHANGE: Enum members are now expected to be `ALL_CAPS` Fixes aws/aws-cdk#2287
1 parent 464b8c6 commit c88080d

44 files changed

Lines changed: 259 additions & 239 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ like any other class.
2121

2222
> NOTE: Due to performance of the hosted JavaScript engine and marshaling costs,
2323
__jsii__ modules are likely to be used for development and build tools, as
24-
oppose to performance-sensitive runtime behavior.
24+
opposed to performance-sensitive runtime behavior.
2525

2626
From Java:
2727

packages/jsii-calc-lib/lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export interface StructWithOnlyOptionals {
9595
* See awslabs/jsii#138
9696
*/
9797
export enum EnumFromScopedModule {
98-
Value1,
99-
Value2
98+
VALUE1,
99+
VALUE2
100100
}
101101

102102
/**

packages/jsii-calc-lib/test/assembly.jsii

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@
136136
"docs": {
137137
"stability": "deprecated"
138138
},
139-
"name": "Value1"
139+
"name": "VALUE1"
140140
},
141141
{
142142
"docs": {
143143
"stability": "deprecated"
144144
},
145-
"name": "Value2"
145+
"name": "VALUE2"
146146
}
147147
],
148148
"name": "EnumFromScopedModule"
@@ -540,5 +540,5 @@
540540
}
541541
},
542542
"version": "0.11.3",
543-
"fingerprint": "jAkwT5aChzSZi3hTeylIFDPL1J8qUy++0B75C5vIA6Y="
543+
"fingerprint": "iggTfEXzBxodU2TEDzkmrmsuEakOvA/UXmOA/8nQboU="
544544
}

packages/jsii-calc/lib/calculator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export namespace composition {
133133
/**
134134
* The .toString() style.
135135
*/
136-
public stringStyle = CompositeOperation.CompositionStringStyle.Normal
136+
public stringStyle = CompositeOperation.CompositionStringStyle.NORMAL
137137

138138
/**
139139
* A set of prefixes to include in a decorated .toString().
@@ -157,9 +157,9 @@ export namespace composition {
157157

158158
toString() {
159159
switch (this.stringStyle) {
160-
case CompositeOperation.CompositionStringStyle.Normal:
160+
case CompositeOperation.CompositionStringStyle.NORMAL:
161161
return this.expression.toString();
162-
case CompositeOperation.CompositionStringStyle.Decorated:
162+
case CompositeOperation.CompositionStringStyle.DECORATED:
163163
return this.decorationPrefixes.join('') + this.expression.toString() + this.decorationPostfixes.join('');
164164
default:
165165
throw new Error(`Unknown string style: ${this.stringStyle}`);
@@ -173,10 +173,10 @@ export namespace composition {
173173
*/
174174
export enum CompositionStringStyle {
175175
/** Normal string expression */
176-
Normal,
176+
NORMAL,
177177

178178
/** Decorated string expression */
179-
Decorated
179+
DECORATED
180180
}
181181
}
182182
}

packages/jsii-calc/lib/compliance.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import base = require('@scope/jsii-calc-base');
2121
const readFile = promisify(fs.readFile);
2222

2323
export enum AllTypesEnum {
24-
MyEnumValue,
25-
YourEnumValue = 100,
26-
ThisIsGreat
24+
MY_ENUM_VALUE,
25+
YOUR_ENUM_VALUE = 100,
26+
THIS_IS_GREAT
2727
}
2828

2929
export enum StringEnum {
@@ -169,7 +169,7 @@ export class AllTypes {
169169
// enum
170170

171171
public optionalEnumValue?: StringEnum;
172-
private enumValue: AllTypesEnum = AllTypesEnum.ThisIsGreat;
172+
private enumValue: AllTypesEnum = AllTypesEnum.THIS_IS_GREAT;
173173

174174
get enumProperty() {
175175
return this.enumValue;
@@ -178,9 +178,9 @@ export class AllTypes {
178178
set enumProperty(value: AllTypesEnum) {
179179
this.enumValue = value;
180180
switch (value) {
181-
case AllTypesEnum.MyEnumValue:
182-
case AllTypesEnum.YourEnumValue:
183-
case AllTypesEnum.ThisIsGreat:
181+
case AllTypesEnum.MY_ENUM_VALUE:
182+
case AllTypesEnum.YOUR_ENUM_VALUE:
183+
case AllTypesEnum.THIS_IS_GREAT:
184184
return;
185185
default:
186186
throw new Error('Invalid enum: ' + value);
@@ -1008,7 +1008,7 @@ export interface ImplictBaseOfBase extends base.BaseProps {
10081008
* See awslabs/jsii#138
10091009
*/
10101010
export class ReferenceEnumFromScopedPackage {
1011-
public foo?: EnumFromScopedModule = EnumFromScopedModule.Value2;
1011+
public foo?: EnumFromScopedModule = EnumFromScopedModule.VALUE2;
10121012

10131013
public loadFoo(): EnumFromScopedModule | undefined {
10141014
return this.foo;
@@ -1594,7 +1594,7 @@ export abstract class PartiallyInitializedThisConsumer {
15941594

15951595
export class ConstructorPassesThisOut {
15961596
constructor(consumer: PartiallyInitializedThisConsumer) {
1597-
const result = consumer.consumePartiallyInitializedThis(this, new Date(0), AllTypesEnum.ThisIsGreat);
1597+
const result = consumer.consumePartiallyInitializedThis(this, new Date(0), AllTypesEnum.THIS_IS_GREAT);
15981598
if (result !== 'OK') {
15991599
throw new Error(`Expected OK but received ${result}`);
16001600
}
@@ -1702,13 +1702,13 @@ export class SingletonString {
17021702
private constructor() { }
17031703

17041704
public isSingletonString(value: string): boolean {
1705-
return value === SingletonStringEnum.SingletonString;
1705+
return value === SingletonStringEnum.SINGLETON_STRING;
17061706
}
17071707
}
17081708
/** A singleton string */
17091709
export enum SingletonStringEnum {
17101710
/** 1337 */
1711-
SingletonString = '3L1T3!'
1711+
SINGLETON_STRING = '3L1T3!'
17121712
}
17131713
/**
17141714
* Verifies that singleton enums are handled correctly
@@ -1718,11 +1718,11 @@ export enum SingletonStringEnum {
17181718
export class SingletonInt {
17191719
private constructor() { }
17201720
public isSingletonInt(value: number): boolean {
1721-
return value === SingletonIntEnum.SingletonInt;
1721+
return value === SingletonIntEnum.SINGLETON_INT;
17221722
}
17231723
}
17241724
/** A singleton integer. */
17251725
export enum SingletonIntEnum {
17261726
/** Elite! */
1727-
SingletonInt = 1337
1727+
SINGLETON_INT = 1337
17281728
}

packages/jsii-calc/lib/stability.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export class ExperimentalClass {
3030
/** @experimental */
3131
export enum ExperimentalEnum {
3232
/** @experimental */
33-
OptionA,
33+
OPTION_A,
3434
/** @experimental */
35-
OptionB
35+
OPTION_B
3636
}
3737

3838
/** @stable */
@@ -64,9 +64,9 @@ export class StableClass {
6464
/** @stable */
6565
export enum StableEnum {
6666
/** @stable */
67-
OptionA,
67+
OPTION_A,
6868
/** @stable */
69-
OptionB
69+
OPTION_B
7070
}
7171

7272
/** @deprecated it just wraps a string */
@@ -98,7 +98,7 @@ export class DeprecatedClass {
9898
/** @deprecated your deprecated selection of bad options */
9999
export enum DeprecatedEnum {
100100
/** @deprecated option A is not great */
101-
OptionA,
101+
OPTION_A,
102102
/** @deprecated option B is kinda bad, too */
103-
OptionB
103+
OPTION_B
104104
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,19 @@
892892
"docs": {
893893
"stability": "experimental"
894894
},
895-
"name": "MyEnumValue"
895+
"name": "MY_ENUM_VALUE"
896896
},
897897
{
898898
"docs": {
899899
"stability": "experimental"
900900
},
901-
"name": "YourEnumValue"
901+
"name": "YOUR_ENUM_VALUE"
902902
},
903903
{
904904
"docs": {
905905
"stability": "experimental"
906906
},
907-
"name": "ThisIsGreat"
907+
"name": "THIS_IS_GREAT"
908908
}
909909
],
910910
"name": "AllTypesEnum"
@@ -2262,14 +2262,14 @@
22622262
"deprecated": "option A is not great",
22632263
"stability": "deprecated"
22642264
},
2265-
"name": "OptionA"
2265+
"name": "OPTION_A"
22662266
},
22672267
{
22682268
"docs": {
22692269
"deprecated": "option B is kinda bad, too",
22702270
"stability": "deprecated"
22712271
},
2272-
"name": "OptionB"
2272+
"name": "OPTION_B"
22732273
}
22742274
],
22752275
"name": "DeprecatedEnum"
@@ -2972,13 +2972,13 @@
29722972
"docs": {
29732973
"stability": "experimental"
29742974
},
2975-
"name": "OptionA"
2975+
"name": "OPTION_A"
29762976
},
29772977
{
29782978
"docs": {
29792979
"stability": "experimental"
29802980
},
2981-
"name": "OptionB"
2981+
"name": "OPTION_B"
29822982
}
29832983
],
29842984
"name": "ExperimentalEnum"
@@ -7179,7 +7179,7 @@
71797179
"stability": "experimental",
71807180
"summary": "Elite!"
71817181
},
7182-
"name": "SingletonInt"
7182+
"name": "SINGLETON_INT"
71837183
}
71847184
],
71857185
"name": "SingletonIntEnum"
@@ -7242,7 +7242,7 @@
72427242
"stability": "experimental",
72437243
"summary": "1337."
72447244
},
7245-
"name": "SingletonString"
7245+
"name": "SINGLETON_STRING"
72467246
}
72477247
],
72487248
"name": "SingletonStringEnum"
@@ -7338,13 +7338,13 @@
73387338
"docs": {
73397339
"stability": "stable"
73407340
},
7341-
"name": "OptionA"
7341+
"name": "OPTION_A"
73427342
},
73437343
{
73447344
"docs": {
73457345
"stability": "stable"
73467346
},
7347-
"name": "OptionB"
7347+
"name": "OPTION_B"
73487348
}
73497349
],
73507350
"name": "StableEnum"
@@ -8759,20 +8759,20 @@
87598759
"stability": "experimental",
87608760
"summary": "Normal string expression."
87618761
},
8762-
"name": "Normal"
8762+
"name": "NORMAL"
87638763
},
87648764
{
87658765
"docs": {
87668766
"stability": "experimental",
87678767
"summary": "Decorated string expression."
87688768
},
8769-
"name": "Decorated"
8769+
"name": "DECORATED"
87708770
}
87718771
],
87728772
"name": "CompositionStringStyle",
87738773
"namespace": "composition.CompositeOperation"
87748774
}
87758775
},
87768776
"version": "0.11.3",
8777-
"fingerprint": "PRTiHZmA0R0OqG2aleNqw5twteIgxeOUgjhzIkQMaxg="
8777+
"fingerprint": "ap5kT9z2b1y6ofObpCic6pDWcRTWCr0ivtq83hsi6ds="
87788778
}

packages/jsii-calc/test/test.calc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ calc.neg(); assert.equal(-3200000, calc.value);
3030

3131
calc.curr = new Multiply(new calcLib.Number(2), calc.curr);
3232
assert.equal(-6400000, calc.value);
33-
calc.stringStyle = composition.CompositeOperation.CompositionStringStyle.Decorated;
33+
calc.stringStyle = composition.CompositeOperation.CompositionStringStyle.DECORATED;
3434
assert.equal(calc.toString(),
3535
'<<[[{{(2 * -(((((1 * ((0 + 10) * 2)) * ((0 + 10) * 2)) * ((0 + 10) * 2)) * ((0 + 10) * 2)) * ((0 + 10) * 2)))}}]]>>');
3636

packages/jsii-diff/test/test.enums.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export = {
99
async 'okay to add a member to an enum'(test: Test) {
1010
await expectNoError(test, `
1111
export enum Foo {
12-
Bar,
13-
Baz,
12+
BAR,
13+
BAZ,
1414
}
1515
`, `
1616
export enum Foo {
17-
Bar,
18-
Baz,
19-
Quux
17+
BAR,
18+
BAZ,
19+
QUUX
2020
}
2121
`);
2222
test.done();
@@ -26,17 +26,17 @@ export = {
2626

2727
async 'not okay to remove a member from an enum'(test: Test) {
2828
await expectError(test,
29-
/member Quux has been removed/,
29+
/member QUUX has been removed/,
3030
`
3131
export enum Foo {
32-
Bar,
33-
Baz,
34-
Quux
32+
BAR,
33+
BAZ,
34+
QUUX
3535
}
3636
`, `
3737
export enum Foo {
38-
Bar,
39-
Baz
38+
BAR,
39+
BAZ
4040
}
4141
`);
4242
test.done();

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,21 @@ public void GetAndSetEnumValues()
260260

261261
calc.Add(9);
262262
calc.Pow(3);
263-
Assert.Equal(CompositionStringStyle.Normal, calc.StringStyle);
264-
calc.StringStyle = CompositionStringStyle.Decorated;
265-
Assert.Equal(CompositionStringStyle.Decorated, calc.StringStyle);
263+
Assert.Equal(CompositionStringStyle.NORMAL, calc.StringStyle);
264+
calc.StringStyle = CompositionStringStyle.DECORATED;
265+
Assert.Equal(CompositionStringStyle.DECORATED, calc.StringStyle);
266266
Assert.Equal("<<[[{{(((1 * (0 + 9)) * (0 + 9)) * (0 + 9))}}]]>>", calc.ToString());
267267
}
268268

269269
[Fact(DisplayName = Prefix + nameof(EnumFromScopedModule))]
270270
public void UseEnumFromScopedModule()
271271
{
272272
ReferenceEnumFromScopedPackage obj = new ReferenceEnumFromScopedPackage();
273-
Assert.Equal(EnumFromScopedModule.Value2, obj.Foo);
274-
obj.Foo = EnumFromScopedModule.Value1;
275-
Assert.Equal(EnumFromScopedModule.Value1, obj.LoadFoo());
276-
obj.SaveFoo(EnumFromScopedModule.Value2);
277-
Assert.Equal(EnumFromScopedModule.Value2, obj.Foo);
273+
Assert.Equal(EnumFromScopedModule.VALUE2, obj.Foo);
274+
obj.Foo = EnumFromScopedModule.VALUE1;
275+
Assert.Equal(EnumFromScopedModule.VALUE1, obj.LoadFoo());
276+
obj.SaveFoo(EnumFromScopedModule.VALUE2);
277+
Assert.Equal(EnumFromScopedModule.VALUE2, obj.Foo);
278278
}
279279

280280
[Fact(DisplayName = Prefix + nameof(UndefinedAndNull))]
@@ -929,7 +929,7 @@ public override String ConsumePartiallyInitializedThis(ConstructorPassesThisOut
929929
{
930930
Assert.NotNull(obj);
931931
Assert.Equal(new DateTime(0), dt);
932-
Assert.Equal(AllTypesEnum.ThisIsGreat, ev);
932+
Assert.Equal(AllTypesEnum.THIS_IS_GREAT, ev);
933933

934934
return "OK";
935935
}

0 commit comments

Comments
 (0)