From f66fa0f4e69b07c7d308837f86ced55fe53ee48d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 28 Oct 2022 18:33:01 +0000 Subject: [PATCH 1/3] chore(site): enable eslint-plugin-eslint-comments --- site/.eslintrc.yaml | 2 ++ site/package.json | 1 + site/yarn.lock | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/site/.eslintrc.yaml b/site/.eslintrc.yaml index 0c9b81714526e..9c60bca004266 100644 --- a/site/.eslintrc.yaml +++ b/site/.eslintrc.yaml @@ -8,6 +8,7 @@ env: extends: - eslint:recommended - plugin:@typescript-eslint/recommended + - plugin:eslint-comments/recommended - plugin:import/recommended - plugin:import/typescript - plugin:react/recommended @@ -60,6 +61,7 @@ rules: "@typescript-eslint/triple-slash-reference": "off" "brace-style": "off" "curly": ["error", "all"] + "eslint-comments/require-description": "error" eqeqeq: error import/default: "off" import/namespace: "off" diff --git a/site/package.json b/site/package.json index b38494f51ddf2..f9757693f16e2 100644 --- a/site/package.json +++ b/site/package.json @@ -103,6 +103,7 @@ "eslint-import-resolver-alias": "1.1.2", "eslint-import-resolver-typescript": "3.5.0", "eslint-plugin-compat": "4.0.2", + "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-jest": "27.0.1", "eslint-plugin-jsx-a11y": "6.6.1", diff --git a/site/yarn.lock b/site/yarn.lock index 69c339576ebb3..011a50a62d2b7 100644 --- a/site/yarn.lock +++ b/site/yarn.lock @@ -6346,6 +6346,14 @@ eslint-plugin-compat@4.0.2: lodash.memoize "4.1.2" semver "7.3.5" +eslint-plugin-eslint-comments@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-3.2.0.tgz#9e1cd7b4413526abb313933071d7aba05ca12ffa" + integrity sha512-0jkOl0hfojIHHmEHgmNdqv4fmh7300NdpA9FFpF7zaoLvB/QeXOGNLIo86oAveJFrfB1p05kC8hpEMHM8DwWVQ== + dependencies: + escape-string-regexp "^1.0.5" + ignore "^5.0.5" + eslint-plugin-import@2.26.0: version "2.26.0" resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz#f812dc47be4f2b72b478a021605a59fc6fe8b88b" @@ -7762,7 +7770,7 @@ ignore@^4.0.3: resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.2.0: +ignore@^5.0.5, ignore@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== From 168760ef71daffd943a4fd7a3fb5bb85399579b1 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 28 Oct 2022 19:32:47 +0000 Subject: [PATCH 2/3] chore: add descriptions to eslint-disable comments --- site/src/components/BuildsTable/BuildsTable.tsx | 3 ++- .../src/components/SearchBarWithFilter/SearchBarWithFilter.tsx | 2 +- site/src/components/UserAutocomplete/UserAutocomplete.tsx | 2 +- site/src/pages/AuditPage/AuditPageView.tsx | 2 +- .../src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx | 3 ++- site/src/pages/WorkspacePage/WorkspacePage.test.tsx | 3 ++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/site/src/components/BuildsTable/BuildsTable.tsx b/site/src/components/BuildsTable/BuildsTable.tsx index 6bf20ef3d2a92..76ab9b93c17a2 100644 --- a/site/src/components/BuildsTable/BuildsTable.tsx +++ b/site/src/components/BuildsTable/BuildsTable.tsx @@ -34,7 +34,8 @@ const groupBuildsByDate = (builds?: TypesGen.WorkspaceBuild[]) => { builds.forEach((build) => { const dateKey = new Date(build.created_at).toDateString() - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + // Unsure why this is here but we probably need to fix it. + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- see above if (buildsByDate[dateKey]) { buildsByDate[dateKey].push(build) } else { diff --git a/site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx b/site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx index 7da46ab4ac22e..2ffe4534804ba 100644 --- a/site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx +++ b/site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx @@ -39,7 +39,7 @@ export const SearchBarWithFilter: React.FC< // debounce query string entry by user // we want the dependency array empty here // as we don't need to redefine the function - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps -- see above const debouncedOnFilter = useCallback( debounce((debouncedQueryString: string) => { onFilter(debouncedQueryString) diff --git a/site/src/components/UserAutocomplete/UserAutocomplete.tsx b/site/src/components/UserAutocomplete/UserAutocomplete.tsx index bd9c05d7816ea..186b8841fb90c 100644 --- a/site/src/components/UserAutocomplete/UserAutocomplete.tsx +++ b/site/src/components/UserAutocomplete/UserAutocomplete.tsx @@ -41,7 +41,7 @@ export const UserAutocomplete: FC = ({ if (value) { sendSearch("SEARCH", { query: value.email }) } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO look into this }, []) const handleFilterChange = debounce( diff --git a/site/src/pages/AuditPage/AuditPageView.tsx b/site/src/pages/AuditPage/AuditPageView.tsx index 824cd9e4df01c..b48a76aa0160e 100644 --- a/site/src/pages/AuditPage/AuditPageView.tsx +++ b/site/src/pages/AuditPage/AuditPageView.tsx @@ -47,7 +47,7 @@ const groupAuditLogsByDate = (auditLogs?: AuditLog[]) => { auditLogs.forEach((auditLog) => { const dateKey = new Date(auditLog.time).toDateString() - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- TODO look into this if (auditLogsByDate[dateKey]) { auditLogsByDate[dateKey].push(auditLog) } else { diff --git a/site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx b/site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx index 57a11e02c5f2a..c6749de7cfc5a 100644 --- a/site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx +++ b/site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-floating-promises */ +/* eslint-disable @typescript-eslint/no-floating-promises -- TODO figure out why this is*/ import { fireEvent, screen, waitFor } from "@testing-library/react" import userEvent from "@testing-library/user-event" import * as API from "api/api" @@ -62,3 +62,4 @@ describe("CreateWorkspacePage", () => { ) }) }) +/* eslint-enable @typescript-eslint/no-floating-promises -- TODO figure out why this is*/ diff --git a/site/src/pages/WorkspacePage/WorkspacePage.test.tsx b/site/src/pages/WorkspacePage/WorkspacePage.test.tsx index 0c55b342f0684..bacd99e967542 100644 --- a/site/src/pages/WorkspacePage/WorkspacePage.test.tsx +++ b/site/src/pages/WorkspacePage/WorkspacePage.test.tsx @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-floating-promises */ +/* eslint-disable @typescript-eslint/no-floating-promises -- TODO look into this */ import { fireEvent, screen, waitFor, within } from "@testing-library/react" import userEvent from "@testing-library/user-event" import EventSourceMock from "eventsourcemock" @@ -349,3 +349,4 @@ describe("WorkspacePage", () => { }) }) }) +/* eslint-enable @typescript-eslint/no-floating-promises -- TODO look into this */ From 60772a24247dcd186991e2360484a24eb96c08a8 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 28 Oct 2022 19:34:18 +0000 Subject: [PATCH 3/3] chore: update eslint-disable comments in main.go --- scripts/apitypings/main.go | 6 +++--- site/src/api/typesGenerated.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/apitypings/main.go b/scripts/apitypings/main.go index 5d27695fc6d43..49555b317210e 100644 --- a/scripts/apitypings/main.go +++ b/scripts/apitypings/main.go @@ -624,7 +624,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) { ValueType: "any", AboveTypeLine: fmt.Sprintf("%s\n%s", indentedComment("Embedded anonymous struct, please fix by naming it"), - indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any"), + indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"), ), }, nil case *types.Map: @@ -736,7 +736,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) { if _, ok := n.Underlying().(*types.Struct); ok { return TypescriptType{ValueType: "any", AboveTypeLine: fmt.Sprintf("%s\n%s", indentedComment(fmt.Sprintf("Named type %q unknown, using \"any\"", n.String())), - indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any"), + indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"), )}, nil } @@ -761,7 +761,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) { intf := ty if intf.Empty() { return TypescriptType{ValueType: "any", - AboveTypeLine: indentedComment("eslint-disable-next-line")}, nil + AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed")}, nil } return TypescriptType{}, xerrors.New("only empty interface types are supported") case *types.TypeParam: diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index cab90e5f8ccac..6b8affde3d827 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -41,9 +41,9 @@ export type AuditDiff = Record // From codersdk/audit.go export interface AuditDiffField { - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed readonly old?: any - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed readonly new?: any readonly secret: boolean } @@ -55,7 +55,7 @@ export interface AuditLog { readonly time: string readonly organization_id: string // Named type "net/netip.Addr" unknown, using "any" - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed readonly ip: any readonly user_agent: string readonly resource_type: ResourceType @@ -384,7 +384,7 @@ export interface Healthcheck { export interface License { readonly id: number readonly uploaded_at: string - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed readonly claims: Record } @@ -577,7 +577,7 @@ export interface Role { // From codersdk/sse.go export interface ServerSentEvent { readonly type: ServerSentEventType - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed readonly data: any }