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

chore: make TS enums strictly PascalCase #26875

Merged
merged 12 commits into from
Feb 1, 2024

Conversation

villebro
Copy link
Member

@villebro villebro commented Jan 30, 2024

SUMMARY

TypeScript enum names and keys should always be PascalCase, which is the commonly accepted best practice (see the official docs: https://www.typescriptlang.org/docs/handbook/enums.html). This PR does the following:

  • Adds ESLint rules to enforce both PascalCase for the enum names and their respective keys.
  • Fix the whole FS codebase, including superset-ui packages/plugins. The enum values have been left in tact so as to not cause a breaking change.

Note, that I've made a few exceptions, where deviating from pascal case makes more sense, especially the locales and currencies, where it felt dangerous and less intuitive to move to pascal case.

TESTING INSTRUCTIONS

  1. Pull the codebase, try to rename a TS enum to snake case, and notice how the linter complains.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@villebro villebro force-pushed the villebro/cleanup-enum branch 2 times, most recently from a2ef0a3 to fed2486 Compare January 30, 2024 01:24
@john-bodley john-bodley added v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch risk:breaking-change Issues or PRs that will introduce breaking changes and removed v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch labels Jan 30, 2024
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: 184 lines in your changes are missing coverage. Please review.

Comparison is base (1f5ae74) 67.24% compared to head (e22ccab) 67.29%.
Report is 22 commits behind head on master.

Files Patch % Lines
...end/src/features/databases/DatabaseModal/index.tsx 30.76% 16 Missing and 2 partials ⚠️
...frontend/src/SqlLab/components/SqlEditor/index.tsx 8.33% 5 Missing and 6 partials ⚠️
...l/AdhocFilterEditPopoverSimpleTabContent/index.tsx 50.00% 7 Missing and 3 partials ⚠️
...SqlLab/components/KeyboardShortcutButton/index.tsx 0.00% 0 Missing and 8 partials ⚠️
...frontend/src/SqlLab/components/ResultSet/index.tsx 36.36% 2 Missing and 5 partials ⚠️
...tend/src/components/Datasource/CollectionTable.tsx 0.00% 3 Missing and 2 partials ⚠️
...end/src/components/Datasource/DatasourceEditor.jsx 0.00% 0 Missing and 5 partials ⚠️
.../controls/ContourControl/ContourPopoverControl.tsx 0.00% 5 Missing ⚠️
...charts/src/Timeseries/Regular/Bar/controlPanel.tsx 0.00% 4 Missing ⚠️
...gin-chart-echarts/src/Timeseries/transformProps.ts 20.00% 0 Missing and 4 partials ⚠️
... and 66 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26875      +/-   ##
==========================================
+ Coverage   67.24%   67.29%   +0.04%     
==========================================
  Files        1895     1894       -1     
  Lines       74248    74246       -2     
  Branches     8257     8256       -1     
==========================================
+ Hits        49929    49963      +34     
+ Misses      22248    22208      -40     
- Partials     2071     2075       +4     
Flag Coverage Δ
javascript 57.10% <49.58%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 25 to 30
enum CHART_STATUS_MAP {
failed = 'danger',
loading = 'warning',
success = 'success',
}
const CHART_STATUS_MAP = {
failed: 'danger',
loading: 'warning',
success: 'success',
};
Copy link
Member Author

Choose a reason for hiding this comment

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

This was really not a proper enum or used as such, so I changed it to a regular object.

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this single override, as it felt sensible to leave the locales and currencies as-is

@michael-s-molina michael-s-molina added the v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch label Jan 31, 2024
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you for the improvement @villebro. I left some first-pass comments.

ScheduledQueries = 'SCHEDULED_QUERIES',
ShareQueriesViaKvStore = 'SHARE_QUERIES_VIA_KV_STORE',
SqllabBackendPersistence = 'SQLLAB_BACKEND_PERSISTENCE',
SqlValidatorsByEngine = 'SQLLAB_BACKEND_PERSISTENCE',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SqlValidatorsByEngine = 'SQLLAB_BACKEND_PERSISTENCE',
SqlValidatorsByEngine = 'SQL_VALIDATORS_BY_ENGINE',

Copy link
Member

Choose a reason for hiding this comment

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

Eagle eyes! How did you even spot this?!

Copy link
Member

Choose a reason for hiding this comment

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

Lots of ☕ apparently! :)

Copy link
Member

Choose a reason for hiding this comment

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

☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM!

@villebro
Copy link
Member Author

I'm gonna go ahead and merge this, as it conflicts extremely easily due to the number of touched files. Thanks for the reviews!

@villebro
Copy link
Member Author

...but I'll leave it open until the end of the working day PST so anyone else can post commentts if they have time to review!

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

Love it, 100% recommend for bed time read if you have insomnia. LGTM!

@rusackas
Copy link
Member

You know when you forget to blink for too long, then it hurts when you do?

I'm halfway done reviewing. My browser hates this PR, but I love that you've done it :D

@@ -332,15 +332,15 @@ export default function sqlLabReducer(state = {}, action) {
},
[actions.REQUEST_QUERY_RESULTS]() {
return alterInObject(state, 'queries', action.query, {
state: QueryState.FETCHING,
state: QueryState.Fetching,
Copy link
Member

Choose a reason for hiding this comment

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

687474703a2f2f696d616765732e68756666696e67746f6e706f73742e636f6d2f323031342d30362d32352d666574636868617070656e2e676966

@villebro
Copy link
Member Author

villebro commented Jan 31, 2024

I'm halfway done reviewing. My browser hates this PR, but I love that you've done it :D

The fact that this PR is 2k LOC, 360+ files and almost crashes the browser shows just how bad this inconsistency problem had gotten over time. I look forward to doing the same for the backend codebase.. shudders

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM!
...passes out

@villebro villebro merged commit 19f8405 into apache:master Feb 1, 2024
31 checks passed
@villebro villebro deleted the villebro/cleanup-enum branch February 1, 2024 01:40
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.0.0 labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels risk:breaking-change Issues or PRs that will introduce breaking changes size/XXL v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🚢 4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants