chore: remove dangling eslint-ignore comments (#14334)

This commit is contained in:
Kayla Washburn-Love
2024-08-19 16:08:53 -06:00
committed by GitHub
parent fa59b30cfb
commit 1c3dc8392e
20 changed files with 1220 additions and 1256 deletions
+35 -38
View File
@@ -646,7 +646,7 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
// Just append these as fields. We should fix this later.
state.Fields = append(state.Fields, tsType.AboveTypeLine)
}
state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s", indent, jsonName, optional, valueType))
state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s;", indent, jsonName, optional, valueType))
}
// This is implemented to ensure the correct order of generics on the
@@ -759,12 +759,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
// }
// }
return TypescriptType{
ValueType: "any",
AboveTypeLine: fmt.Sprintf("%s\n%s",
indentedComment("Embedded anonymous struct, please fix by naming it"),
// Linter needs to be disabled here, or else it will complain about the "any" type.
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Anonymously embedded struct"),
),
AboveTypeLine: indentedComment("Embedded anonymous struct, please fix by naming it"),
ValueType: "unknown",
}, nil
case *types.Map:
// map[string][string] -> Record<string, string>
@@ -815,16 +811,11 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
}
genValue := ""
// Always wrap in parentheses for proper scoped types.
// Running prettier on this output will remove redundant parenthesis,
// so this makes our decision-making easier.
// The example that breaks without this is:
// readonly readonly string[][]
if underlying.GenericValue != "" {
genValue = "(readonly " + underlying.GenericValue + "[])"
genValue = "Readonly<Array<" + underlying.GenericValue + ">>"
}
return TypescriptType{
ValueType: "(readonly " + underlying.ValueType + "[])",
ValueType: "Readonly<Array<" + underlying.ValueType + ">>",
GenericValue: genValue,
AboveTypeLine: underlying.AboveTypeLine,
GenericTypes: underlying.GenericTypes,
@@ -858,6 +849,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
return TypescriptType{ValueType: "boolean"}, nil
case "github.com/coder/serpent.Duration":
return TypescriptType{ValueType: "number"}, nil
case "net/netip.Addr":
return TypescriptType{ValueType: "string"}, nil
case "net/url.URL":
return TypescriptType{ValueType: "string"}, nil
case "time.Time":
@@ -889,6 +882,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
return TypescriptType{ValueType: "HealthSection"}, nil
case "github.com/coder/coder/v2/codersdk.ProvisionerDaemon":
return TypescriptType{ValueType: "ProvisionerDaemon"}, nil
// Some very unfortunate `any` types that leaked into the frontend.
case "tailscale.com/tailcfg.DERPNode",
"tailscale.com/derp.ServerInfoMessage",
"tailscale.com/tailcfg.DERPRegion",
"tailscale.com/net/netcheck.Report",
"github.com/spf13/pflag.Value":
return TypescriptType{AboveTypeLine: indentedComment("TODO: narrow this type"), ValueType: "any"}, nil
}
// Some hard codes are a bit trickier.
@@ -965,15 +966,15 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
// If it's a struct, just use the name of the struct type
if _, ok := n.Underlying().(*types.Struct); ok {
// External structs cannot be introspected, as we only parse the codersdk package.
// You can handle your type manually in the switch list above, otherwise "any" will be used.
// An easy way to fix this is to pull your external type into `codersdk` package, then it will
// be known by the generator.
return TypescriptType{ValueType: "any", AboveTypeLine: fmt.Sprintf("%s\n%s",
indentedComment(fmt.Sprintf("Named type %q unknown, using \"any\"", n.String())),
// Linter needs to be disabled here, or else it will complain about the "any" type.
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type"),
)}, nil
// External structs cannot be introspected, as we only parse the codersdk
// package. You can handle your type manually in the switch list above,
// otherwise `unknown` will be used. An easy way to fix this is to pull
// your external type into codersdk, then it will be known by the
// generator.
return TypescriptType{
AboveTypeLine: indentedComment(fmt.Sprintf("external type %q, using \"unknown\"", n.String())),
ValueType: "unknown",
}, nil
}
// Defer to the underlying type.
@@ -1002,20 +1003,16 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
// This field is 'interface{}'. We can't infer any type from 'interface{}'
// so just use "any" as the type.
return TypescriptType{
ValueType: "any",
AboveTypeLine: fmt.Sprintf("%s\n%s",
indentedComment("Empty interface{} type, cannot resolve the type."),
// Linter needs to be disabled here, or else it will complain about the "any" type.
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}"),
),
AboveTypeLine: indentedComment("empty interface{} type, falling back to unknown"),
ValueType: "unknown",
}, nil
}
// Interfaces are difficult to determine the JSON type, so just return
// an 'any'.
// an 'unknown'.
return TypescriptType{
ValueType: "any",
AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type."),
AboveTypeLine: indentedComment("interface type, falling back to unknown"),
ValueType: "unknown",
Optional: false,
}, nil
case *types.TypeParam:
@@ -1040,13 +1037,13 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
// If we don't have the type constraint defined somewhere in the package,
// then we have to resort to using any.
return TypescriptType{
AboveTypeLine: fmt.Sprintf("// %q is an external type, falling back to unknown", name),
GenericTypes: map[string]string{
ty.Obj().Name(): "any",
ty.Obj().Name(): "unknown",
},
GenericValue: ty.Obj().Name(),
ValueType: "any",
AboveTypeLine: fmt.Sprintf("// %q is an external type, so we use any", name),
Optional: false,
GenericValue: ty.Obj().Name(),
ValueType: "unknown",
Optional: false,
}, nil
}
// Include the builtin for this type to reference
@@ -1097,7 +1094,7 @@ func (Generator) isBuiltIn(name string) (bool, string) {
case "comparable":
// To be complete, we include "any". Kinda sucks :(
return true, "export type comparable = boolean | number | string | any"
case "any":
case "any", "unknown":
// This is supported in typescript, we don't need to write anything
return true, ""
default:
+1 -1
View File
@@ -43,7 +43,7 @@ func TestGeneration(t *testing.T) {
output = strings.TrimSpace(output)
if *updateGoldenFiles {
// nolint:gosec
err := os.WriteFile(golden, []byte(output), 0o644)
err := os.WriteFile(golden, []byte(output+"\n"), 0o644)
require.NoError(t, err, "write golden file")
} else {
require.Equal(t, expectedString, output, "matched output")
+1 -1
View File
@@ -1,5 +1,5 @@
// From codersdk/enums.go
export type EnumSliceType = (readonly Enum[])
export type EnumSliceType = Readonly<Array<Enum>>
// From codersdk/enums.go
export type Enum = "bar" | "baz" | "foo" | "qux"
+5 -5
View File
@@ -1,18 +1,18 @@
// From codersdk/genericmap.go
export interface Buzz {
readonly foo: Foo
readonly bazz: string
readonly foo: Foo;
readonly bazz: string;
}
// From codersdk/genericmap.go
export interface Foo {
readonly bar: string
readonly bar: string;
}
// From codersdk/genericmap.go
export interface FooBuzz<R extends Custom> {
readonly something: (readonly R[])
readonly something: Readonly<Array<R>>;
}
// From codersdk/genericmap.go
export type Custom = Foo | Buzz
export type Custom = Foo | Buzz
+16 -16
View File
@@ -1,41 +1,41 @@
// From codersdk/generics.go
export interface Complex<C extends comparable, S extends Single, T extends Custom> {
readonly dynamic: Fields<C, boolean, string, S>
readonly order: FieldsDiffOrder<C, string, S, T>
readonly comparable: C
readonly single: S
readonly static: Static
readonly dynamic: Fields<C, boolean, string, S>;
readonly order: FieldsDiffOrder<C, string, S, T>;
readonly comparable: C;
readonly single: S;
readonly static: Static;
}
// From codersdk/generics.go
export interface Dynamic<A extends any, S extends Single> {
readonly dynamic: Fields<boolean, A, string, S>
readonly comparable: boolean
readonly dynamic: Fields<boolean, A, string, S>;
readonly comparable: boolean;
}
// From codersdk/generics.go
export interface Fields<C extends comparable, A extends any, T extends Custom, S extends Single> {
readonly comparable: C
readonly any: A
readonly custom: T
readonly again: T
readonly single_constraint: S
readonly comparable: C;
readonly any: A;
readonly custom: T;
readonly again: T;
readonly single_constraint: S;
}
// From codersdk/generics.go
export interface FieldsDiffOrder<A extends any, C extends comparable, S extends Single, T extends Custom> {
readonly Fields: Fields<C, A, T, S>
readonly Fields: Fields<C, A, T, S>;
}
// From codersdk/generics.go
export interface Static {
readonly static: Fields<string, number, number, string>
readonly static: Fields<string, number, number, string>;
}
// From codersdk/generics.go
export type Custom = string | boolean | number | (readonly string[]) | null
export type Custom = string | boolean | number | Readonly<Array<string>> | null
// From codersdk/generics.go
export type Single = string
export type comparable = boolean | number | string | any
export type comparable = boolean | number | string | any
+4 -4
View File
@@ -1,10 +1,10 @@
// From codersdk/genericslice.go
export interface Bar {
readonly Bar: string
readonly Bar: string;
}
// From codersdk/genericslice.go
export interface Foo<R extends any> {
readonly Slice: (readonly R[])
readonly TwoD: (readonly (readonly R[])[])
}
readonly Slice: Readonly<Array<R>>;
readonly TwoD: Readonly<Array<Readonly<Array<R>>>>;
}
+2 -5
View File
@@ -241,8 +241,7 @@ export const sshIntoWorkspace = async (
},
write: cp.stdin.write.bind(cp.stdin),
});
// eslint-disable-next-line no-console -- Helpful for debugging
cp.stderr.on("data", (data) => console.log(data.toString()));
cp.stderr.on("data", (data) => console.info(data.toString()));
cp.stdout.on("readable", (...args) => {
proxyStream.emit("readable", ...args);
if (cp.stdout.readableLength > 0) {
@@ -355,10 +354,8 @@ export const downloadCoderVersion = async (
},
},
);
// eslint-disable-next-line no-console -- Needed for debugging
cp.stderr.on("data", (data) => console.error(data.toString()));
// eslint-disable-next-line no-console -- Needed for debugging
cp.stdout.on("data", (data) => console.log(data.toString()));
cp.stdout.on("data", (data) => console.info(data.toString()));
cp.on("close", (code) => {
if (code === 0) {
resolve();
-2
View File
@@ -1,6 +1,5 @@
import * as fs from "node:fs/promises";
import type { Writable } from "node:stream";
/* eslint-disable no-console -- Logging is sort of the whole point here */
import type {
FullConfig,
FullResult,
@@ -170,5 +169,4 @@ const reportError = (error: TestError) => {
}
};
// eslint-disable-next-line no-unused-vars -- Playwright config uses it
export default CoderReporter;
-1
View File
@@ -62,7 +62,6 @@ test("web terminal", async ({ context, page }) => {
);
} catch (error) {
const pageContent = await terminal.content();
// eslint-disable-next-line no-console -- Let's see what is inside of xterm-rows
console.error("Unable to find echoed text:", pageContent);
throw error;
}
+1149 -1159
View File
File diff suppressed because it is too large Load Diff
@@ -33,10 +33,6 @@ export const CodeExample: FC<CodeExampleProps> = ({
};
return (
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions --
Expanding clickable area of CodeExample for better ergonomics, but don't
want to change the semantics of the HTML elements being rendered
*/
<div
css={styles.container}
className={className}
@@ -15,8 +15,6 @@ async function fillInputField(inputElement: HTMLElement, text: string) {
// Tried everything under the sun to catch the state changes the proper way,
// but the only way to get around it for now might be to manually make React
// DOM aware of the changes
// eslint-disable-next-line testing-library/no-unnecessary-act -- have to make sure state updates don't slip through cracks
return act(() => userEvent.type(inputElement, text));
}
-2
View File
@@ -1,5 +1,3 @@
/* eslint-disable eslint-comments/disable-enable-pair -- Solve below */
/* eslint-disable import/no-duplicates -- https://github.com/date-fns/date-fns/issues/1677 */
import formatRelative from "date-fns/formatRelative";
import subDays from "date-fns/subDays";
-2
View File
@@ -1,5 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps -- false positives */
import { css } from "@emotion/css";
import { type Theme, useTheme } from "@emotion/react";
import { type DependencyList, useMemo } from "react";
@@ -1,7 +1,6 @@
import Button, { type ButtonProps } from "@mui/material/Button";
import { forwardRef } from "react";
// eslint-disable-next-line react/display-name -- Name is inferred from variable name
export const AgentButton = forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => {
const { children, ...buttonProps } = props;
@@ -11,15 +11,14 @@ interface GroupMember {
* @returns a diff with the 'members' key flattened to be an array of user_ids
*/
export const determineGroupDiff = (auditLogDiff: AuditDiff): AuditDiff => {
const old = auditLogDiff.members?.old as GroupMember[] | undefined;
const new_ = auditLogDiff.members?.new as GroupMember[] | undefined;
return {
...auditLogDiff,
members: {
old: auditLogDiff.members?.old?.map(
(groupMember: GroupMember) => groupMember.user_id,
),
new: auditLogDiff.members?.new?.map(
(groupMember: GroupMember) => groupMember.user_id,
),
old: old?.map((groupMember) => groupMember.user_id),
new: new_?.map((groupMember) => groupMember.user_id),
secret: auditLogDiff.members?.secret,
},
};
@@ -12,7 +12,6 @@ const getTagLabel = (tag: string) => {
aws: "AWS",
google: "Google Cloud",
};
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- this can be undefined
return labelByTag[tag] ?? tag;
};
-1
View File
@@ -1,4 +1,3 @@
/* eslint-disable jsx-a11y/heading-has-content -- infer from props */
import { css } from "@emotion/css";
import { useTheme } from "@emotion/react";
import CheckCircleOutlined from "@mui/icons-material/CheckCircleOutlined";
@@ -42,11 +42,9 @@ export const StartingUnknown: Story = {
transitionStats: {
// HACK: the codersdk type generator doesn't support null values, but this
// can be null when the template is new.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Read comment above
// @ts-ignore-error
// @ts-expect-error
P50: null,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Read comment above
// @ts-ignore-error
// @ts-expect-error
P95: null,
},
},
-1
View File
@@ -98,7 +98,6 @@ export const withAuthProvider = (Story: FC, { parameters }: StoryContext) => {
if (!parameters.user) {
throw new Error("You forgot to add `parameters.user` to your story");
}
// eslint-disable-next-line react-hooks/rules-of-hooks -- decorators are components
const queryClient = useQueryClient();
queryClient.setQueryData(meKey, parameters.user);
queryClient.setQueryData(hasFirstUserKey, true);