Skip to content

Commit 19f8405

Browse files
authored
chore: make TS enums strictly PascalCase (#26875)
1 parent 959a5a5 commit 19f8405

362 files changed

Lines changed: 2001 additions & 2031 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.

superset-frontend/.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ module.exports = {
9393
'@typescript-eslint/ban-ts-ignore': 0,
9494
'@typescript-eslint/ban-ts-comment': 0, // disabled temporarily
9595
'@typescript-eslint/ban-types': 0, // disabled temporarily
96+
'@typescript-eslint/naming-convention': [
97+
'error',
98+
{
99+
selector: 'enum',
100+
format: ['PascalCase'],
101+
},
102+
{
103+
selector: 'enumMember',
104+
format: ['PascalCase'],
105+
},
106+
],
96107
'@typescript-eslint/no-empty-function': 0,
97108
'@typescript-eslint/no-explicit-any': 0,
98109
'@typescript-eslint/no-use-before-define': 1, // disabled temporarily

superset-frontend/packages/superset-ui-chart-controls/src/components/ColumnTypeLabel/ColumnTypeLabel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export function ColumnTypeLabel({ type }: ColumnTypeLabelProps) {
5757

5858
if (type === '' || type === 'expression') {
5959
typeIcon = <FunctionSvg aria-label={t('function type icon')} />;
60-
} else if (type === GenericDataType.STRING) {
60+
} else if (type === GenericDataType.String) {
6161
typeIcon = <StringSvg aria-label={t('string type icon')} />;
62-
} else if (type === GenericDataType.NUMERIC) {
62+
} else if (type === GenericDataType.Numeric) {
6363
typeIcon = <NumSvg aria-label={t('numeric type icon')} />;
64-
} else if (type === GenericDataType.BOOLEAN) {
64+
} else if (type === GenericDataType.Boolean) {
6565
typeIcon = <BooleanSvg aria-label={t('boolean type icon')} />;
66-
} else if (type === GenericDataType.TEMPORAL) {
66+
} else if (type === GenericDataType.Temporal) {
6767
typeIcon = <ClockCircleOutlined aria-label={t('temporal type icon')} />;
6868
}
6969

superset-frontend/packages/superset-ui-chart-controls/src/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const DATASET_TIME_COLUMN_OPTION: ColumnMeta = {
4343
verbose_name: COLUMN_NAME_ALIASES[DTTM_ALIAS],
4444
column_name: DTTM_ALIAS,
4545
type: 'TIMESTAMP',
46-
type_generic: GenericDataType.TEMPORAL,
46+
type_generic: GenericDataType.Temporal,
4747
description: t(
4848
'A reference to the [Time] configuration, taking granularity into account',
4949
),
@@ -53,12 +53,12 @@ export const QUERY_TIME_COLUMN_OPTION: QueryColumn = {
5353
column_name: DTTM_ALIAS,
5454
is_dttm: true,
5555
type: 'TIMESTAMP',
56-
type_generic: GenericDataType.TEMPORAL,
56+
type_generic: GenericDataType.Temporal,
5757
};
5858

5959
export const QueryModeLabel = {
60-
[QueryMode.aggregate]: t('Aggregate'),
61-
[QueryMode.raw]: t('Raw records'),
60+
[QueryMode.Aggregate]: t('Aggregate'),
61+
[QueryMode.Raw]: t('Raw records'),
6262
};
6363

6464
export const DEFAULT_SORT_SERIES_DATA: SortSeriesData = {

superset-frontend/packages/superset-ui-chart-controls/src/fixtures.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const TestDataset: Dataset = {
3737
is_dttm: false,
3838
python_date_format: null,
3939
type: 'BIGINT',
40-
type_generic: GenericDataType.NUMERIC,
40+
type_generic: GenericDataType.Numeric,
4141
verbose_name: null,
4242
warning_markdown: null,
4343
},
@@ -55,7 +55,7 @@ export const TestDataset: Dataset = {
5555
is_dttm: false,
5656
python_date_format: null,
5757
type: 'VARCHAR(16)',
58-
type_generic: GenericDataType.STRING,
58+
type_generic: GenericDataType.String,
5959
verbose_name: '',
6060
warning_markdown: null,
6161
},
@@ -73,7 +73,7 @@ export const TestDataset: Dataset = {
7373
is_dttm: false,
7474
python_date_format: null,
7575
type: 'VARCHAR(10)',
76-
type_generic: GenericDataType.STRING,
76+
type_generic: GenericDataType.String,
7777
verbose_name: null,
7878
warning_markdown: null,
7979
},
@@ -91,7 +91,7 @@ export const TestDataset: Dataset = {
9191
is_dttm: true,
9292
python_date_format: null,
9393
type: 'TIMESTAMP WITHOUT TIME ZONE',
94-
type_generic: GenericDataType.TEMPORAL,
94+
type_generic: GenericDataType.Temporal,
9595
verbose_name: null,
9696
warning_markdown: null,
9797
},
@@ -109,7 +109,7 @@ export const TestDataset: Dataset = {
109109
is_dttm: false,
110110
python_date_format: null,
111111
type: 'VARCHAR(255)',
112-
type_generic: GenericDataType.STRING,
112+
type_generic: GenericDataType.String,
113113
verbose_name: null,
114114
warning_markdown: null,
115115
},

superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/customControls.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function isForcedCategorical(controls: ControlStateMapping): boolean {
6060
checkColumnType(
6161
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
6262
controls?.datasource?.datasource,
63-
[GenericDataType.NUMERIC],
63+
[GenericDataType.Numeric],
6464
) && !!controls?.xAxisForceCategorical?.value
6565
);
6666
}
@@ -71,7 +71,7 @@ function isSortable(controls: ControlStateMapping): boolean {
7171
checkColumnType(
7272
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
7373
controls?.datasource?.datasource,
74-
[GenericDataType.STRING, GenericDataType.BOOLEAN],
74+
[GenericDataType.String, GenericDataType.Boolean],
7575
)
7676
);
7777
}
@@ -173,7 +173,7 @@ export const xAxisForceCategoricalControl = {
173173
checkColumnType(
174174
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
175175
controls?.datasource?.datasource,
176-
[GenericDataType.NUMERIC],
176+
[GenericDataType.Numeric],
177177
),
178178
shouldMapStateToProps: () => true,
179179
},

superset-frontend/packages/superset-ui-chart-controls/src/types.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,29 +420,29 @@ export type SectionOverrides = {
420420

421421
// Ref:
422422
// - superset-frontend/src/explore/components/ConditionalFormattingControl.tsx
423-
export enum COMPARATOR {
424-
NONE = 'None',
425-
GREATER_THAN = '>',
426-
LESS_THAN = '<',
427-
GREATER_OR_EQUAL = '≥',
428-
LESS_OR_EQUAL = '≤',
429-
EQUAL = '=',
430-
NOT_EQUAL = '≠',
431-
BETWEEN = '< x <',
432-
BETWEEN_OR_EQUAL = '≤ x ≤',
433-
BETWEEN_OR_LEFT_EQUAL = '≤ x <',
434-
BETWEEN_OR_RIGHT_EQUAL = '< x ≤',
423+
export enum Comparator {
424+
None = 'None',
425+
GreaterThan = '>',
426+
LessThan = '<',
427+
GreaterOrEqual = '≥',
428+
LessOrEqual = '≤',
429+
Equal = '=',
430+
NotEqual = '≠',
431+
Between = '< x <',
432+
BetweenOrEqual = '≤ x ≤',
433+
BetweenOrLeftEqual = '≤ x <',
434+
BetweenOrRightEqual = '< x ≤',
435435
}
436436

437-
export const MULTIPLE_VALUE_COMPARATORS = [
438-
COMPARATOR.BETWEEN,
439-
COMPARATOR.BETWEEN_OR_EQUAL,
440-
COMPARATOR.BETWEEN_OR_LEFT_EQUAL,
441-
COMPARATOR.BETWEEN_OR_RIGHT_EQUAL,
437+
export const MultipleValueComparators = [
438+
Comparator.Between,
439+
Comparator.BetweenOrEqual,
440+
Comparator.BetweenOrLeftEqual,
441+
Comparator.BetweenOrRightEqual,
442442
];
443443

444444
export type ConditionalFormattingConfig = {
445-
operator?: COMPARATOR;
445+
operator?: Comparator;
446446
targetValue?: number;
447447
targetValueLeft?: number;
448448
targetValueRight?: number;

superset-frontend/packages/superset-ui-chart-controls/src/utils/getColorFormatters.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import memoizeOne from 'memoize-one';
2020
import { addAlpha, DataRecord } from '@superset-ui/core';
2121
import {
2222
ColorFormatters,
23-
COMPARATOR,
23+
Comparator,
2424
ConditionalFormattingConfig,
25-
MULTIPLE_VALUE_COMPARATORS,
25+
MultipleValueComparators,
2626
} from '../types';
2727

2828
export const round = (num: number, precision = 0) =>
@@ -75,20 +75,20 @@ export const getColorFunction = (
7575
return () => undefined;
7676
}
7777
if (
78-
MULTIPLE_VALUE_COMPARATORS.includes(operator) &&
78+
MultipleValueComparators.includes(operator) &&
7979
(targetValueLeft === undefined || targetValueRight === undefined)
8080
) {
8181
return () => undefined;
8282
}
8383
if (
84-
operator !== COMPARATOR.NONE &&
85-
!MULTIPLE_VALUE_COMPARATORS.includes(operator) &&
84+
operator !== Comparator.None &&
85+
!MultipleValueComparators.includes(operator) &&
8686
targetValue === undefined
8787
) {
8888
return () => undefined;
8989
}
9090
switch (operator) {
91-
case COMPARATOR.NONE:
91+
case Comparator.None:
9292
minOpacity = MIN_OPACITY_UNBOUNDED;
9393
comparatorFunction = (value: number, allValues: number[]) => {
9494
const cutoffValue = Math.min(...allValues);
@@ -98,37 +98,37 @@ export const getColorFunction = (
9898
: false;
9999
};
100100
break;
101-
case COMPARATOR.GREATER_THAN:
101+
case Comparator.GreaterThan:
102102
comparatorFunction = (value: number, allValues: number[]) =>
103103
value > targetValue!
104104
? { cutoffValue: targetValue!, extremeValue: Math.max(...allValues) }
105105
: false;
106106
break;
107-
case COMPARATOR.LESS_THAN:
107+
case Comparator.LessThan:
108108
comparatorFunction = (value: number, allValues: number[]) =>
109109
value < targetValue!
110110
? { cutoffValue: targetValue!, extremeValue: Math.min(...allValues) }
111111
: false;
112112
break;
113-
case COMPARATOR.GREATER_OR_EQUAL:
113+
case Comparator.GreaterOrEqual:
114114
comparatorFunction = (value: number, allValues: number[]) =>
115115
value >= targetValue!
116116
? { cutoffValue: targetValue!, extremeValue: Math.max(...allValues) }
117117
: false;
118118
break;
119-
case COMPARATOR.LESS_OR_EQUAL:
119+
case Comparator.LessOrEqual:
120120
comparatorFunction = (value: number, allValues: number[]) =>
121121
value <= targetValue!
122122
? { cutoffValue: targetValue!, extremeValue: Math.min(...allValues) }
123123
: false;
124124
break;
125-
case COMPARATOR.EQUAL:
125+
case Comparator.Equal:
126126
comparatorFunction = (value: number) =>
127127
value === targetValue!
128128
? { cutoffValue: targetValue!, extremeValue: targetValue! }
129129
: false;
130130
break;
131-
case COMPARATOR.NOT_EQUAL:
131+
case Comparator.NotEqual:
132132
comparatorFunction = (value: number, allValues: number[]) => {
133133
if (value === targetValue!) {
134134
return false;
@@ -144,25 +144,25 @@ export const getColorFunction = (
144144
};
145145
};
146146
break;
147-
case COMPARATOR.BETWEEN:
147+
case Comparator.Between:
148148
comparatorFunction = (value: number) =>
149149
value > targetValueLeft! && value < targetValueRight!
150150
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
151151
: false;
152152
break;
153-
case COMPARATOR.BETWEEN_OR_EQUAL:
153+
case Comparator.BetweenOrEqual:
154154
comparatorFunction = (value: number) =>
155155
value >= targetValueLeft! && value <= targetValueRight!
156156
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
157157
: false;
158158
break;
159-
case COMPARATOR.BETWEEN_OR_LEFT_EQUAL:
159+
case Comparator.BetweenOrLeftEqual:
160160
comparatorFunction = (value: number) =>
161161
value >= targetValueLeft! && value < targetValueRight!
162162
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
163163
: false;
164164
break;
165-
case COMPARATOR.BETWEEN_OR_RIGHT_EQUAL:
165+
case Comparator.BetweenOrRightEqual:
166166
comparatorFunction = (value: number) =>
167167
value > targetValueLeft! && value <= targetValueRight!
168168
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
@@ -197,9 +197,9 @@ export const getColorFormatters = memoizeOne(
197197
(acc: ColorFormatters, config: ConditionalFormattingConfig) => {
198198
if (
199199
config?.column !== undefined &&
200-
(config?.operator === COMPARATOR.NONE ||
200+
(config?.operator === Comparator.None ||
201201
(config?.operator !== undefined &&
202-
(MULTIPLE_VALUE_COMPARATORS.includes(config?.operator)
202+
(MultipleValueComparators.includes(config?.operator)
203203
? config?.targetValueLeft !== undefined &&
204204
config?.targetValueRight !== undefined
205205
: config?.targetValue !== undefined)))

superset-frontend/packages/superset-ui-chart-controls/test/components/ColumnOption.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('ColumnOption', () => {
6565
column: {
6666
column_name: 'foo',
6767
type: 'VARCHAR',
68-
type_generic: GenericDataType.STRING,
68+
type_generic: GenericDataType.String,
6969
},
7070
}),
7171
);
@@ -92,11 +92,11 @@ describe('ColumnOption', () => {
9292
it('dttm column has correct column label if showType is true', () => {
9393
props.showType = true;
9494
props.column.expression = undefined;
95-
props.column.type_generic = GenericDataType.TEMPORAL;
95+
props.column.type_generic = GenericDataType.Temporal;
9696
wrapper = shallow(factory(props));
9797
expect(wrapper.find(ColumnTypeLabel)).toHaveLength(1);
9898
expect(wrapper.find(ColumnTypeLabel).props().type).toBe(
99-
GenericDataType.TEMPORAL,
99+
GenericDataType.Temporal,
100100
);
101101
});
102102
});

superset-frontend/packages/superset-ui-chart-controls/test/components/ColumnTypeLabel.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ColumnTypeLabel, ColumnTypeLabelProps } from '../../src';
2525

2626
describe('ColumnOption', () => {
2727
const defaultProps = {
28-
type: GenericDataType.STRING,
28+
type: GenericDataType.String,
2929
};
3030

3131
const props = { ...defaultProps };
@@ -40,15 +40,15 @@ describe('ColumnOption', () => {
4040
);
4141
});
4242
it('string type shows ABC icon', () => {
43-
renderColumnTypeLabel({ type: GenericDataType.STRING });
43+
renderColumnTypeLabel({ type: GenericDataType.String });
4444
expect(screen.getByLabelText('string type icon')).toBeVisible();
4545
});
4646
it('int type shows # icon', () => {
47-
renderColumnTypeLabel({ type: GenericDataType.NUMERIC });
47+
renderColumnTypeLabel({ type: GenericDataType.Numeric });
4848
expect(screen.getByLabelText('numeric type icon')).toBeVisible();
4949
});
5050
it('bool type shows 1|0 icon', () => {
51-
renderColumnTypeLabel({ type: GenericDataType.BOOLEAN });
51+
renderColumnTypeLabel({ type: GenericDataType.Boolean });
5252
expect(screen.getByLabelText('boolean type icon')).toBeVisible();
5353
});
5454
it('expression type shows function icon', () => {
@@ -60,7 +60,7 @@ describe('ColumnOption', () => {
6060
expect(screen.getByLabelText('unknown type icon')).toBeVisible();
6161
});
6262
it('datetime type displays', () => {
63-
renderColumnTypeLabel({ type: GenericDataType.TEMPORAL });
63+
renderColumnTypeLabel({ type: GenericDataType.Temporal });
6464
expect(screen.getByLabelText('temporal type icon')).toBeVisible();
6565
});
6666
});

superset-frontend/packages/superset-ui-chart-controls/test/utils/checkColumnType.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ import { checkColumnType, TestDataset } from '../../src';
2121

2222
test('checkColumnType columns from a Dataset', () => {
2323
expect(
24-
checkColumnType('num', TestDataset, [GenericDataType.NUMERIC]),
24+
checkColumnType('num', TestDataset, [GenericDataType.Numeric]),
2525
).toEqual(true);
26-
expect(checkColumnType('num', TestDataset, [GenericDataType.STRING])).toEqual(
26+
expect(checkColumnType('num', TestDataset, [GenericDataType.String])).toEqual(
2727
false,
2828
);
2929
expect(
30-
checkColumnType('gender', TestDataset, [GenericDataType.STRING]),
30+
checkColumnType('gender', TestDataset, [GenericDataType.String]),
3131
).toEqual(true);
3232
expect(
33-
checkColumnType('gender', TestDataset, [GenericDataType.NUMERIC]),
33+
checkColumnType('gender', TestDataset, [GenericDataType.Numeric]),
3434
).toEqual(false);
3535
});
3636

3737
test('checkColumnType from a QueryResponse', () => {
3838
expect(
39-
checkColumnType('Column 1', testQueryResponse, [GenericDataType.STRING]),
39+
checkColumnType('Column 1', testQueryResponse, [GenericDataType.String]),
4040
).toEqual(true);
4141
expect(
42-
checkColumnType('Column 1', testQueryResponse, [GenericDataType.NUMERIC]),
42+
checkColumnType('Column 1', testQueryResponse, [GenericDataType.Numeric]),
4343
).toEqual(false);
4444
});
4545

0 commit comments

Comments
 (0)