Skip to content

chore: remove dangling eslint-ignore comments #14334

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

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions scripts/apitypings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/apitypings/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion scripts/apitypings/testdata/enums/enums.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 5 additions & 5 deletions scripts/apitypings/testdata/genericmap/genericmap.ts
Original file line number Diff line number Diff line change
@@ -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
32 changes: 16 additions & 16 deletions scripts/apitypings/testdata/generics/generics.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions scripts/apitypings/testdata/genericslice/genericslice.ts
Original file line number Diff line number Diff line change
@@ -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>>>>;
}
7 changes: 2 additions & 5 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions site/e2e/reporter.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -170,5 +169,4 @@ const reportError = (error: TestError) => {
}
};

// eslint-disable-next-line no-unused-vars -- Playwright config uses it
export default CoderReporter;
1 change: 0 additions & 1 deletion site/e2e/tests/webTerminal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading
Loading