From a2e0190d20c4732497964caa67f1d470249f5b76 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 28 Sep 2022 20:52:08 +0200 Subject: [PATCH 1/4] Add additional eslint rules --- airbyte-webapp/.eslintrc | 101 ---------------- airbyte-webapp/.eslintrc.js | 112 ++++++++++++++++++ airbyte-webapp/src/hooks/useLoadingState.tsx | 2 +- .../src/hooks/useTypesafeReducer.ts | 2 +- .../cloud/lib/auth/GoogleAuthService.ts | 2 +- .../components/RemainingCredits.tsx | 2 +- .../components/DestinationForm.tsx | 2 +- .../components/CreateConnectorModal.tsx | 4 +- .../components/WebHookForm.tsx | 6 +- .../components/SourceForm.tsx | 4 +- .../services/workspaces/WorkspacesService.tsx | 2 +- airbyte-webapp/src/test-utils/testutils.tsx | 4 +- .../Connector/ConnectorCard/ConnectorCard.tsx | 2 +- .../Connector/ServiceForm/ServiceForm.tsx | 4 +- .../Sections/auth/useOauthFlowAdapter.tsx | 2 +- .../PreferencesForm/PreferencesForm.tsx | 4 +- 16 files changed, 133 insertions(+), 122 deletions(-) delete mode 100644 airbyte-webapp/.eslintrc create mode 100644 airbyte-webapp/.eslintrc.js diff --git a/airbyte-webapp/.eslintrc b/airbyte-webapp/.eslintrc deleted file mode 100644 index 42ab74d3eb6d..000000000000 --- a/airbyte-webapp/.eslintrc +++ /dev/null @@ -1,101 +0,0 @@ -{ - "extends": [ - "react-app", - "plugin:@typescript-eslint/recommended", - "plugin:jest/recommended", - "prettier", - "plugin:prettier/recommended", - "plugin:css-modules/recommended", - "plugin:jsx-a11y/recommended" - ], - "plugins": ["react", "@typescript-eslint", "prettier", "unused-imports", "css-modules", "jsx-a11y"], - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "rules": { - "jsx-a11y/label-has-associated-control": "error", - "curly": "warn", - "css-modules/no-undef-class": "off", - "css-modules/no-unused-class": ["error", { "camelCase": true }], - "dot-location": "warn", - "dot-notation": "warn", - "eqeqeq": "error", - "prettier/prettier": "warn", - "unused-imports/no-unused-imports": "warn", - "no-else-return": "warn", - "no-lonely-if": "warn", - "no-inner-declarations": "off", - "no-unused-vars": "off", - "no-useless-computed-key": "warn", - "no-useless-return": "warn", - "no-var": "warn", - "object-shorthand": ["warn", "always"], - "prefer-arrow-callback": "warn", - "prefer-const": "warn", - "prefer-destructuring": ["warn", { "AssignmentExpression": { "array": true } }], - "prefer-object-spread": "warn", - "prefer-template": "warn", - "spaced-comment": ["warn", "always", { "markers": ["/"] }], - "yoda": "warn", - "import/order": [ - "warn", - { - "newlines-between": "always", - "groups": ["type", "builtin", "external", "internal", ["parent", "sibling"], "index"], - "pathGroupsExcludedImportTypes": ["builtin"], - "pathGroups": [ - { - "pattern": "components{/**,}", - "group": "internal" - }, - { - "pattern": "+(config|core|hooks|locales|packages|pages|services|types|utils|views){/**,}", - "group": "internal", - "position": "after" - } - ], - "alphabetize": { - "order": "asc" /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */, - "caseInsensitive": true /* ignore case. Options: [true, false] */ - } - } - ], - "@typescript-eslint/array-type": ["warn", { "default": "array-simple" }], - "@typescript-eslint/ban-ts-comment": [ - "warn", - { - "ts-expect-error": "allow-with-description" - } - ], - "@typescript-eslint/ban-types": "warn", - "@typescript-eslint/consistent-indexed-object-style": ["warn", "record"], - "@typescript-eslint/consistent-type-definitions": ["warn", "interface"], - "@typescript-eslint/no-unused-vars": "warn", - "react/function-component-definition": [ - "warn", - { - "namedComponents": "arrow-function", - "unnamedComponents": "arrow-function" - } - ], - "jest/consistent-test-it": ["warn", { "fn": "it", "withinDescribe": "it" }], - "react/jsx-boolean-value": "warn", - "react/jsx-curly-brace-presence": "warn", - "react/jsx-fragments": "warn", - "react/jsx-no-useless-fragment": ["warn", { "allowExpressions": true }], - "react/self-closing-comp": "warn" - }, - "parser": "@typescript-eslint/parser", - "overrides": [ - { - "files": ["scripts/**/*"], - "rules": { - "@typescript-eslint/no-var-requires": "off" - } - } - ] -} diff --git a/airbyte-webapp/.eslintrc.js b/airbyte-webapp/.eslintrc.js new file mode 100644 index 000000000000..7a02512f731f --- /dev/null +++ b/airbyte-webapp/.eslintrc.js @@ -0,0 +1,112 @@ +module.exports = { + extends: [ + "react-app", + "plugin:@typescript-eslint/recommended", + "plugin:jest/recommended", + "prettier", + "plugin:prettier/recommended", + "plugin:css-modules/recommended", + "plugin:jsx-a11y/recommended", + ], + plugins: ["react", "@typescript-eslint", "prettier", "unused-imports", "css-modules", "jsx-a11y"], + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + ecmaFeatures: { + jsx: true, + }, + }, + rules: { + "jsx-a11y/label-has-associated-control": "error", + curly: "warn", + "css-modules/no-undef-class": "off", + "css-modules/no-unused-class": ["error", { camelCase: true }], + "dot-location": "warn", + "dot-notation": "warn", + eqeqeq: "error", + "prettier/prettier": "warn", + "unused-imports/no-unused-imports": "warn", + "no-else-return": "warn", + "no-lonely-if": "warn", + "no-inner-declarations": "off", + "no-unused-vars": "off", + "no-useless-computed-key": "warn", + "no-useless-return": "warn", + "no-var": "warn", + "object-shorthand": ["warn", "always"], + "prefer-arrow-callback": "warn", + "prefer-const": "warn", + "prefer-destructuring": ["warn", { AssignmentExpression: { array: true } }], + "prefer-object-spread": "warn", + "prefer-template": "warn", + "spaced-comment": ["warn", "always", { markers: ["/"] }], + yoda: "warn", + "import/order": [ + "warn", + { + "newlines-between": "always", + groups: ["type", "builtin", "external", "internal", ["parent", "sibling"], "index"], + pathGroupsExcludedImportTypes: ["builtin"], + pathGroups: [ + { + pattern: "components{/**,}", + group: "internal", + }, + { + pattern: "+(config|core|hooks|locales|packages|pages|services|types|utils|views){/**,}", + group: "internal", + position: "after", + }, + ], + alphabetize: { + order: "asc" /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */, + caseInsensitive: true /* ignore case. Options: [true, false] */, + }, + }, + ], + "@typescript-eslint/array-type": ["warn", { default: "array-simple" }], + "@typescript-eslint/ban-ts-comment": [ + "warn", + { + "ts-expect-error": "allow-with-description", + }, + ], + "@typescript-eslint/ban-types": "warn", + "@typescript-eslint/consistent-indexed-object-style": ["warn", "record"], + "@typescript-eslint/consistent-type-definitions": ["warn", "interface"], + "@typescript-eslint/no-unused-vars": "warn", + "react/function-component-definition": [ + "warn", + { + namedComponents: "arrow-function", + unnamedComponents: "arrow-function", + }, + ], + "jest/consistent-test-it": ["warn", { fn: "it", withinDescribe: "it" }], + "react/jsx-boolean-value": "warn", + "react/jsx-curly-brace-presence": "warn", + "react/jsx-fragments": "warn", + "react/jsx-no-useless-fragment": ["warn", { allowExpressions: true }], + "react/self-closing-comp": "warn", + }, + parser: "@typescript-eslint/parser", + overrides: [ + { + files: ["scripts/**/*"], + rules: { + "@typescript-eslint/no-var-requires": "off", + }, + }, + { + files: ["src/**/*"], + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.json", + }, + rules: { + "@typescript-eslint/await-thenable": "warn", + "@typescript-eslint/no-unnecessary-type-assertion": "warn", + }, + }, + ], +}; diff --git a/airbyte-webapp/src/hooks/useLoadingState.tsx b/airbyte-webapp/src/hooks/useLoadingState.tsx index c5ab8a2e1001..cb002923d061 100644 --- a/airbyte-webapp/src/hooks/useLoadingState.tsx +++ b/airbyte-webapp/src/hooks/useLoadingState.tsx @@ -26,7 +26,7 @@ const useLoadingState = (): { setIsLoading(true); setShowFeedback(false); - await action(); + action(); setIsLoading(false); setShowFeedback(true); diff --git a/airbyte-webapp/src/hooks/useTypesafeReducer.ts b/airbyte-webapp/src/hooks/useTypesafeReducer.ts index 9cd34532496d..886c8860ddc2 100644 --- a/airbyte-webapp/src/hooks/useTypesafeReducer.ts +++ b/airbyte-webapp/src/hooks/useTypesafeReducer.ts @@ -13,7 +13,7 @@ function useTypesafeReducer { - const user = await this.getCurrentUser(); + const user = this.getCurrentUser(); if (user) { await this.reauthenticate(email, password); diff --git a/airbyte-webapp/src/packages/cloud/views/credits/CreditsPage/components/RemainingCredits.tsx b/airbyte-webapp/src/packages/cloud/views/credits/CreditsPage/components/RemainingCredits.tsx index 6a61d38c8248..7bee5c9ef446 100644 --- a/airbyte-webapp/src/packages/cloud/views/credits/CreditsPage/components/RemainingCredits.tsx +++ b/airbyte-webapp/src/packages/cloud/views/credits/CreditsPage/components/RemainingCredits.tsx @@ -109,7 +109,7 @@ const RemainingCredits: React.FC = ({ selfServiceCheckoutEnabled }) => { successUrl: successUrl.href, cancelUrl: window.location.href, }); - await analytics.track(Namespace.CREDITS, Action.CHECKOUT_START, { + analytics.track(Namespace.CREDITS, Action.CHECKOUT_START, { actionDescription: "Checkout Start", }); // Forward to stripe as soon as we created a checkout session successfully diff --git a/airbyte-webapp/src/pages/DestinationPage/pages/CreateDestinationPage/components/DestinationForm.tsx b/airbyte-webapp/src/pages/DestinationPage/pages/CreateDestinationPage/components/DestinationForm.tsx index fce89f9ee2df..2264fcd38288 100644 --- a/airbyte-webapp/src/pages/DestinationPage/pages/CreateDestinationPage/components/DestinationForm.tsx +++ b/airbyte-webapp/src/pages/DestinationPage/pages/CreateDestinationPage/components/DestinationForm.tsx @@ -69,7 +69,7 @@ export const DestinationForm: React.FC = ({ }; const onSubmitForm = async (values: { name: string; serviceType: string }) => { - await onSubmit({ + onSubmit({ ...values, destinationDefinitionId: destinationDefinitionSpecification?.destinationDefinitionId, }); diff --git a/airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/CreateConnectorModal.tsx b/airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/CreateConnectorModal.tsx index 61bbeb1c16e3..680f05e22dfd 100644 --- a/airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/CreateConnectorModal.tsx +++ b/airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/CreateConnectorModal.tsx @@ -117,8 +117,8 @@ const CreateConnectorModal: React.FC = ({ onClose, onSubmit, errorMessag validateOnBlur validateOnChange validationSchema={validationSchema} - onSubmit={async (values, { setSubmitting }) => { - await onSubmit(values); + onSubmit={(values, { setSubmitting }) => { + onSubmit(values); setSubmitting(false); }} > diff --git a/airbyte-webapp/src/pages/SettingsPage/pages/NotificationPage/components/WebHookForm.tsx b/airbyte-webapp/src/pages/SettingsPage/pages/NotificationPage/components/WebHookForm.tsx index 9027b267fc9c..bfb6bdeb2f1b 100644 --- a/airbyte-webapp/src/pages/SettingsPage/pages/NotificationPage/components/WebHookForm.tsx +++ b/airbyte-webapp/src/pages/SettingsPage/pages/NotificationPage/components/WebHookForm.tsx @@ -97,11 +97,11 @@ const WebHookForm: React.FC = ({ webhook, onSubmit, successMes validateOnBlur validateOnChange={false} validationSchema={webhookValidationSchema} - onSubmit={async (values: WebhookPayload) => { + onSubmit={(values: WebhookPayload) => { if (equal(webhook, values)) { - await onTest(values); + onTest(values); } else { - await onSubmit(values); + onSubmit(values); } }} > diff --git a/airbyte-webapp/src/pages/SourcesPage/pages/CreateSourcePage/components/SourceForm.tsx b/airbyte-webapp/src/pages/SourcesPage/pages/CreateSourcePage/components/SourceForm.tsx index 83005ce12988..3715618b0c1e 100644 --- a/airbyte-webapp/src/pages/SourcesPage/pages/CreateSourcePage/components/SourceForm.tsx +++ b/airbyte-webapp/src/pages/SourcesPage/pages/CreateSourcePage/components/SourceForm.tsx @@ -69,8 +69,8 @@ export const SourceForm: React.FC = ({ }); }; - const onSubmitForm = async (values: ServiceFormValues) => { - await onSubmit({ + const onSubmitForm = (values: ServiceFormValues) => { + onSubmit({ ...values, sourceDefinitionId: sourceDefinitionSpecification?.sourceDefinitionId, }); diff --git a/airbyte-webapp/src/services/workspaces/WorkspacesService.tsx b/airbyte-webapp/src/services/workspaces/WorkspacesService.tsx index ebde26c29202..8a7010a58300 100644 --- a/airbyte-webapp/src/services/workspaces/WorkspacesService.tsx +++ b/airbyte-webapp/src/services/workspaces/WorkspacesService.tsx @@ -38,7 +38,7 @@ const useSelectWorkspace = (): ((workspace?: string | null | Workspace) => void) } else { navigate(`/${RoutePaths.Workspaces}/${workspace}`); } - await queryClient.removeQueries(SCOPE_WORKSPACE); + queryClient.removeQueries(SCOPE_WORKSPACE); }, [navigate, queryClient] ); diff --git a/airbyte-webapp/src/test-utils/testutils.tsx b/airbyte-webapp/src/test-utils/testutils.tsx index f330e0cb569b..3412db4a54da 100644 --- a/airbyte-webapp/src/test-utils/testutils.tsx +++ b/airbyte-webapp/src/test-utils/testutils.tsx @@ -49,8 +49,8 @@ export async function render< }; let renderResult: RenderResult; - await act(async () => { - renderResult = await rtlRender(
{ui}
, { wrapper: Wrapper, ...renderOptions }); + act(() => { + renderResult = rtlRender(
{ui}
, { wrapper: Wrapper, ...renderOptions }); }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.tsx b/airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.tsx index 9f8d2573f85e..041d81ea1510 100644 --- a/airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.tsx +++ b/airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.tsx @@ -86,7 +86,7 @@ export const ConnectorCard: React.FC = (props) => { ); const onFormSubmit = useCallback( - async (values: ServiceFormValues) => { + (values: ServiceFormValues) => { const valuesToSend = getValues(values); - await onSubmit(valuesToSend); + onSubmit(valuesToSend); clearFormChange(formId); }, diff --git a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx index 72c35e878ac3..0c4ce0f4eb8d 100644 --- a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx +++ b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx @@ -87,7 +87,7 @@ function useFormikOauthAdapter(connector: ConnectorDefinitionSpecification): { return acc; }, {} as Record); - await run(oauthInputParams); + run(oauthInputParams); }, }; } diff --git a/airbyte-webapp/src/views/Settings/PreferencesForm/PreferencesForm.tsx b/airbyte-webapp/src/views/Settings/PreferencesForm/PreferencesForm.tsx index d286eaa5adea..bac20190b0aa 100644 --- a/airbyte-webapp/src/views/Settings/PreferencesForm/PreferencesForm.tsx +++ b/airbyte-webapp/src/views/Settings/PreferencesForm/PreferencesForm.tsx @@ -83,8 +83,8 @@ const PreferencesForm: React.FC = ({ validateOnBlur validateOnChange={false} validationSchema={preferencesValidationSchema} - onSubmit={async (values) => { - await onSubmit(values); + onSubmit={(values) => { + onSubmit(values); }} > {({ isSubmitting, values, handleChange, setFieldValue, resetForm, isValid, dirty }) => ( From 969bbf66d863804a97e7828022412e862fa2b15f Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 28 Sep 2022 20:57:36 +0200 Subject: [PATCH 2/4] Add comment --- airbyte-webapp/.eslintrc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airbyte-webapp/.eslintrc.js b/airbyte-webapp/.eslintrc.js index 7a02512f731f..3b2ad8b82f07 100644 --- a/airbyte-webapp/.eslintrc.js +++ b/airbyte-webapp/.eslintrc.js @@ -98,6 +98,8 @@ module.exports = { }, }, { + // Only applies to files in src. Rules should be in here that are requiring type information + // and thus require the below parserOptions. files: ["src/**/*"], parserOptions: { tsconfigRootDir: __dirname, From 490b9a340b5e90486af1d4bdc8113a3193887af9 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 29 Sep 2022 22:11:31 +0200 Subject: [PATCH 3/4] Restore async await act --- airbyte-webapp/src/test-utils/testutils.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte-webapp/src/test-utils/testutils.tsx b/airbyte-webapp/src/test-utils/testutils.tsx index 3412db4a54da..77172f9af3bb 100644 --- a/airbyte-webapp/src/test-utils/testutils.tsx +++ b/airbyte-webapp/src/test-utils/testutils.tsx @@ -49,7 +49,7 @@ export async function render< }; let renderResult: RenderResult; - act(() => { + await act(async () => { renderResult = rtlRender(
{ui}
, { wrapper: Wrapper, ...renderOptions }); }); From 236499c1819eef707de831c52d0b97030dcc8b61 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 29 Sep 2022 22:20:43 +0200 Subject: [PATCH 4/4] Fix broken gradle reference --- airbyte-webapp/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte-webapp/build.gradle b/airbyte-webapp/build.gradle index 79d12834e23d..cb773a1d4542 100644 --- a/airbyte-webapp/build.gradle +++ b/airbyte-webapp/build.gradle @@ -22,7 +22,7 @@ node { npm_run_build { inputs.files commonConfigs - inputs.file '.eslintrc' + inputs.file '.eslintrc.js' inputs.dir 'public' inputs.dir 'src'