From c1bf93a41a50347b48994c552e79d1a74b05b7b1 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 19 Jan 2023 15:27:55 -0500 Subject: [PATCH 1/2] chore(site): align ESLint config to typescript-eslint's recommended-requiring-type-checking --- site/.eslintrc.yaml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/site/.eslintrc.yaml b/site/.eslintrc.yaml index c467e18627595..bca94f7465bae 100644 --- a/site/.eslintrc.yaml +++ b/site/.eslintrc.yaml @@ -8,6 +8,7 @@ env: extends: - eslint:recommended - plugin:@typescript-eslint/recommended + - plugin:@typescript-eslint/recommended-requiring-type-checking - plugin:eslint-comments/recommended - plugin:import/recommended - plugin:import/typescript @@ -35,29 +36,18 @@ root: true rules: "@typescript-eslint/brace-style": ["error", "1tbs", { "allowSingleLine": false }] - "@typescript-eslint/camelcase": "off" - "@typescript-eslint/explicit-function-return-type": "off" - "@typescript-eslint/explicit-module-boundary-types": "error" "@typescript-eslint/method-signature-style": ["error", "property"] - "@typescript-eslint/no-floating-promises": error - "@typescript-eslint/no-invalid-void-type": error # We're disabling the `no-namespace` rule to use a pattern of defining an interface, # and then defining functions that operate on that data via namespace. This is helpful for # dealing with immutable objects. This is a common pattern that shows up in some other # large TypeScript projects, like VSCode. # More details: https://github.com/coder/m/pull/9720#discussion_r697609528 "@typescript-eslint/no-namespace": "off" - "@typescript-eslint/no-unnecessary-boolean-literal-compare": error - "@typescript-eslint/no-unnecessary-condition": warn - "@typescript-eslint/no-unnecessary-type-assertion": warn "@typescript-eslint/no-unused-vars": - error - argsIgnorePattern: "^_" varsIgnorePattern: "^_" ignoreRestSiblings: true - "@typescript-eslint/no-use-before-define": "off" - "@typescript-eslint/object-curly-spacing": ["error", "always"] - "@typescript-eslint/triple-slash-reference": "off" "brace-style": "off" "curly": ["error", "all"] "eslint-comments/require-description": "error" From 5727a88892e7cfd1614b6045ee7b6f38615a830e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 19 Jan 2023 15:44:52 -0500 Subject: [PATCH 2/2] Fixed immediately fixable rules, and TODO-diabled the rest --- site/.eslintrc.yaml | 20 +++++++++++++++++++ site/src/api/api.ts | 6 ++---- .../LicenseBanner/LicenseBanner.test.tsx | 4 ++-- .../TemplateSettingsPage.test.tsx | 2 +- site/src/pages/UsersPage/UsersPage.test.tsx | 2 +- .../WorkspacesPage/WorkspacesPage.test.tsx | 2 +- .../src/xServices/users/searchUserXService.ts | 4 +--- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/site/.eslintrc.yaml b/site/.eslintrc.yaml index bca94f7465bae..3b28b76232635 100644 --- a/site/.eslintrc.yaml +++ b/site/.eslintrc.yaml @@ -37,6 +37,26 @@ rules: "@typescript-eslint/brace-style": ["error", "1tbs", { "allowSingleLine": false }] "@typescript-eslint/method-signature-style": ["error", "property"] + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-misused-promises": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-unsafe-argument": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-unsafe-assignment": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-unsafe-call": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-unsafe-member-access": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/no-unsafe-return": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/require-await": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/restrict-plus-operands": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/restrict-template-expressions": "off" + # TODO: Investigate whether to enable this rule & fix and/or disable all its complaints + "@typescript-eslint/unbound-method": "off" # We're disabling the `no-namespace` rule to use a pattern of defining an interface, # and then defining functions that operate on that data via namespace. This is helpful for # dealing with immutable objects. This is a common pattern that shows up in some other diff --git a/site/src/api/api.ts b/site/src/api/api.ts index f1798e2886f33..93c6478ad1f20 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -20,8 +20,7 @@ export const hardCodedCSRFCookie = (): string => { export const withDefaultFeatures = ( fs: Partial, ): TypesGen.Entitlements["features"] => { - for (const k in TypesGen.FeatureNames) { - const feature = k as TypesGen.FeatureName + for (const feature of TypesGen.FeatureNames) { // Skip fields that are already filled. if (fs[feature] !== undefined) { continue @@ -152,8 +151,7 @@ export const getTokens = async (): Promise => { } export const deleteAPIKey = async (keyId: string): Promise => { - const response = await axios.delete("/api/v2/users/me/keys/" + keyId) - return response.data + await axios.delete("/api/v2/users/me/keys/" + keyId) } export const getUsers = async ( diff --git a/site/src/components/LicenseBanner/LicenseBanner.test.tsx b/site/src/components/LicenseBanner/LicenseBanner.test.tsx index f45ac75d0ffa6..477e0dead6174 100644 --- a/site/src/components/LicenseBanner/LicenseBanner.test.tsx +++ b/site/src/components/LicenseBanner/LicenseBanner.test.tsx @@ -9,8 +9,8 @@ import { Language } from "./LicenseBannerView" describe("LicenseBanner", () => { it("does not show when there are no warnings", async () => { render() - const bannerPillSingular = await screen.queryByText(Language.licenseIssue) - const bannerPillPlural = await screen.queryByText(Language.licenseIssues(2)) + const bannerPillSingular = screen.queryByText(Language.licenseIssue) + const bannerPillPlural = screen.queryByText(Language.licenseIssues(2)) expect(bannerPillSingular).toBe(null) expect(bannerPillPlural).toBe(null) }) diff --git a/site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx b/site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx index e0608628d315a..bab264530a146 100644 --- a/site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx +++ b/site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx @@ -65,7 +65,7 @@ const fillAndSubmitForm = async ({ await userEvent.clear(maxTtlField) await userEvent.type(maxTtlField, default_ttl_ms.toString()) - const allowCancelJobsField = await screen.getByRole("checkbox") + const allowCancelJobsField = screen.getByRole("checkbox") // checkbox is checked by default, so it must be clicked to get unchecked if (!allow_user_cancel_workspace_jobs) { await userEvent.click(allowCancelJobsField) diff --git a/site/src/pages/UsersPage/UsersPage.test.tsx b/site/src/pages/UsersPage/UsersPage.test.tsx index 12051f02ab7c2..41fe027b8b8d5 100644 --- a/site/src/pages/UsersPage/UsersPage.test.tsx +++ b/site/src/pages/UsersPage/UsersPage.test.tsx @@ -255,7 +255,7 @@ describe("UsersPage", () => { expect(API.getUsers).toBeCalledWith({ offset: 0, limit: 25, q: "" }), ) - const pageButtons = await container.querySelectorAll( + const pageButtons = container.querySelectorAll( `button[name="Page button"]`, ) // count handler says there are 2 pages of results diff --git a/site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx b/site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx index 3d73efa33518a..e63f549ecd5ea 100644 --- a/site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx +++ b/site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx @@ -49,7 +49,7 @@ describe("WorkspacesPage", () => { name: "Previous page", }) expect(prevPage).toBeDisabled() - const pageButtons = await container.querySelectorAll( + const pageButtons = container.querySelectorAll( `button[name="Page button"]`, ) expect(pageButtons.length).toBe(2) diff --git a/site/src/xServices/users/searchUserXService.ts b/site/src/xServices/users/searchUserXService.ts index 4840126895b13..a80e763dfda78 100644 --- a/site/src/xServices/users/searchUserXService.ts +++ b/site/src/xServices/users/searchUserXService.ts @@ -51,9 +51,7 @@ export const searchUserMachine = createMachine( { services: { searchUsers: async (_, { query }) => - await ( - await getUsers(queryToFilter(query)) - ).users, + (await getUsers(queryToFilter(query))).users, }, actions: { assignSearchResults: assign({