Skip to content

Commit 1c3dc83

Browse files
authored
chore: remove dangling eslint-ignore comments (#14334)
1 parent fa59b30 commit 1c3dc83

File tree

20 files changed

+1220
-1256
lines changed

20 files changed

+1220
-1256
lines changed

scripts/apitypings/main.go

+35-38
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
646646
// Just append these as fields. We should fix this later.
647647
state.Fields = append(state.Fields, tsType.AboveTypeLine)
648648
}
649-
state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s", indent, jsonName, optional, valueType))
649+
state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s;", indent, jsonName, optional, valueType))
650650
}
651651

652652
// 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) {
759759
// }
760760
// }
761761
return TypescriptType{
762-
ValueType: "any",
763-
AboveTypeLine: fmt.Sprintf("%s\n%s",
764-
indentedComment("Embedded anonymous struct, please fix by naming it"),
765-
// Linter needs to be disabled here, or else it will complain about the "any" type.
766-
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Anonymously embedded struct"),
767-
),
762+
AboveTypeLine: indentedComment("Embedded anonymous struct, please fix by naming it"),
763+
ValueType: "unknown",
768764
}, nil
769765
case *types.Map:
770766
// map[string][string] -> Record<string, string>
@@ -815,16 +811,11 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
815811
}
816812
genValue := ""
817813

818-
// Always wrap in parentheses for proper scoped types.
819-
// Running prettier on this output will remove redundant parenthesis,
820-
// so this makes our decision-making easier.
821-
// The example that breaks without this is:
822-
// readonly readonly string[][]
823814
if underlying.GenericValue != "" {
824-
genValue = "(readonly " + underlying.GenericValue + "[])"
815+
genValue = "Readonly<Array<" + underlying.GenericValue + ">>"
825816
}
826817
return TypescriptType{
827-
ValueType: "(readonly " + underlying.ValueType + "[])",
818+
ValueType: "Readonly<Array<" + underlying.ValueType + ">>",
828819
GenericValue: genValue,
829820
AboveTypeLine: underlying.AboveTypeLine,
830821
GenericTypes: underlying.GenericTypes,
@@ -858,6 +849,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
858849
return TypescriptType{ValueType: "boolean"}, nil
859850
case "github.com/coder/serpent.Duration":
860851
return TypescriptType{ValueType: "number"}, nil
852+
case "net/netip.Addr":
853+
return TypescriptType{ValueType: "string"}, nil
861854
case "net/url.URL":
862855
return TypescriptType{ValueType: "string"}, nil
863856
case "time.Time":
@@ -889,6 +882,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
889882
return TypescriptType{ValueType: "HealthSection"}, nil
890883
case "github.com/coder/coder/v2/codersdk.ProvisionerDaemon":
891884
return TypescriptType{ValueType: "ProvisionerDaemon"}, nil
885+
886+
// Some very unfortunate `any` types that leaked into the frontend.
887+
case "tailscale.com/tailcfg.DERPNode",
888+
"tailscale.com/derp.ServerInfoMessage",
889+
"tailscale.com/tailcfg.DERPRegion",
890+
"tailscale.com/net/netcheck.Report",
891+
"github.com/spf13/pflag.Value":
892+
return TypescriptType{AboveTypeLine: indentedComment("TODO: narrow this type"), ValueType: "any"}, nil
892893
}
893894

894895
// Some hard codes are a bit trickier.
@@ -965,15 +966,15 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
965966

966967
// If it's a struct, just use the name of the struct type
967968
if _, ok := n.Underlying().(*types.Struct); ok {
968-
// External structs cannot be introspected, as we only parse the codersdk package.
969-
// You can handle your type manually in the switch list above, otherwise "any" will be used.
970-
// An easy way to fix this is to pull your external type into `codersdk` package, then it will
971-
// be known by the generator.
972-
return TypescriptType{ValueType: "any", AboveTypeLine: fmt.Sprintf("%s\n%s",
973-
indentedComment(fmt.Sprintf("Named type %q unknown, using \"any\"", n.String())),
974-
// Linter needs to be disabled here, or else it will complain about the "any" type.
975-
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type"),
976-
)}, nil
969+
// External structs cannot be introspected, as we only parse the codersdk
970+
// package. You can handle your type manually in the switch list above,
971+
// otherwise `unknown` will be used. An easy way to fix this is to pull
972+
// your external type into codersdk, then it will be known by the
973+
// generator.
974+
return TypescriptType{
975+
AboveTypeLine: indentedComment(fmt.Sprintf("external type %q, using \"unknown\"", n.String())),
976+
ValueType: "unknown",
977+
}, nil
977978
}
978979

979980
// Defer to the underlying type.
@@ -1002,20 +1003,16 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
10021003
// This field is 'interface{}'. We can't infer any type from 'interface{}'
10031004
// so just use "any" as the type.
10041005
return TypescriptType{
1005-
ValueType: "any",
1006-
AboveTypeLine: fmt.Sprintf("%s\n%s",
1007-
indentedComment("Empty interface{} type, cannot resolve the type."),
1008-
// Linter needs to be disabled here, or else it will complain about the "any" type.
1009-
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}"),
1010-
),
1006+
AboveTypeLine: indentedComment("empty interface{} type, falling back to unknown"),
1007+
ValueType: "unknown",
10111008
}, nil
10121009
}
10131010

10141011
// Interfaces are difficult to determine the JSON type, so just return
1015-
// an 'any'.
1012+
// an 'unknown'.
10161013
return TypescriptType{
1017-
ValueType: "any",
1018-
AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type."),
1014+
AboveTypeLine: indentedComment("interface type, falling back to unknown"),
1015+
ValueType: "unknown",
10191016
Optional: false,
10201017
}, nil
10211018
case *types.TypeParam:
@@ -1040,13 +1037,13 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
10401037
// If we don't have the type constraint defined somewhere in the package,
10411038
// then we have to resort to using any.
10421039
return TypescriptType{
1040+
AboveTypeLine: fmt.Sprintf("// %q is an external type, falling back to unknown", name),
10431041
GenericTypes: map[string]string{
1044-
ty.Obj().Name(): "any",
1042+
ty.Obj().Name(): "unknown",
10451043
},
1046-
GenericValue: ty.Obj().Name(),
1047-
ValueType: "any",
1048-
AboveTypeLine: fmt.Sprintf("// %q is an external type, so we use any", name),
1049-
Optional: false,
1044+
GenericValue: ty.Obj().Name(),
1045+
ValueType: "unknown",
1046+
Optional: false,
10501047
}, nil
10511048
}
10521049
// Include the builtin for this type to reference
@@ -1097,7 +1094,7 @@ func (Generator) isBuiltIn(name string) (bool, string) {
10971094
case "comparable":
10981095
// To be complete, we include "any". Kinda sucks :(
10991096
return true, "export type comparable = boolean | number | string | any"
1100-
case "any":
1097+
case "any", "unknown":
11011098
// This is supported in typescript, we don't need to write anything
11021099
return true, ""
11031100
default:

scripts/apitypings/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestGeneration(t *testing.T) {
4343
output = strings.TrimSpace(output)
4444
if *updateGoldenFiles {
4545
// nolint:gosec
46-
err := os.WriteFile(golden, []byte(output), 0o644)
46+
err := os.WriteFile(golden, []byte(output+"\n"), 0o644)
4747
require.NoError(t, err, "write golden file")
4848
} else {
4949
require.Equal(t, expectedString, output, "matched output")

scripts/apitypings/testdata/enums/enums.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// From codersdk/enums.go
2-
export type EnumSliceType = (readonly Enum[])
2+
export type EnumSliceType = Readonly<Array<Enum>>
33

44
// From codersdk/enums.go
55
export type Enum = "bar" | "baz" | "foo" | "qux"
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// From codersdk/genericmap.go
22
export interface Buzz {
3-
readonly foo: Foo
4-
readonly bazz: string
3+
readonly foo: Foo;
4+
readonly bazz: string;
55
}
66

77
// From codersdk/genericmap.go
88
export interface Foo {
9-
readonly bar: string
9+
readonly bar: string;
1010
}
1111

1212
// From codersdk/genericmap.go
1313
export interface FooBuzz<R extends Custom> {
14-
readonly something: (readonly R[])
14+
readonly something: Readonly<Array<R>>;
1515
}
1616

1717
// From codersdk/genericmap.go
18-
export type Custom = Foo | Buzz
18+
export type Custom = Foo | Buzz
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
// From codersdk/generics.go
22
export interface Complex<C extends comparable, S extends Single, T extends Custom> {
3-
readonly dynamic: Fields<C, boolean, string, S>
4-
readonly order: FieldsDiffOrder<C, string, S, T>
5-
readonly comparable: C
6-
readonly single: S
7-
readonly static: Static
3+
readonly dynamic: Fields<C, boolean, string, S>;
4+
readonly order: FieldsDiffOrder<C, string, S, T>;
5+
readonly comparable: C;
6+
readonly single: S;
7+
readonly static: Static;
88
}
99

1010
// From codersdk/generics.go
1111
export interface Dynamic<A extends any, S extends Single> {
12-
readonly dynamic: Fields<boolean, A, string, S>
13-
readonly comparable: boolean
12+
readonly dynamic: Fields<boolean, A, string, S>;
13+
readonly comparable: boolean;
1414
}
1515

1616
// From codersdk/generics.go
1717
export interface Fields<C extends comparable, A extends any, T extends Custom, S extends Single> {
18-
readonly comparable: C
19-
readonly any: A
20-
readonly custom: T
21-
readonly again: T
22-
readonly single_constraint: S
18+
readonly comparable: C;
19+
readonly any: A;
20+
readonly custom: T;
21+
readonly again: T;
22+
readonly single_constraint: S;
2323
}
2424

2525
// From codersdk/generics.go
2626
export interface FieldsDiffOrder<A extends any, C extends comparable, S extends Single, T extends Custom> {
27-
readonly Fields: Fields<C, A, T, S>
27+
readonly Fields: Fields<C, A, T, S>;
2828
}
2929

3030
// From codersdk/generics.go
3131
export interface Static {
32-
readonly static: Fields<string, number, number, string>
32+
readonly static: Fields<string, number, number, string>;
3333
}
3434

3535
// From codersdk/generics.go
36-
export type Custom = string | boolean | number | (readonly string[]) | null
36+
export type Custom = string | boolean | number | Readonly<Array<string>> | null
3737

3838
// From codersdk/generics.go
3939
export type Single = string
4040

41-
export type comparable = boolean | number | string | any
41+
export type comparable = boolean | number | string | any
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// From codersdk/genericslice.go
22
export interface Bar {
3-
readonly Bar: string
3+
readonly Bar: string;
44
}
55

66
// From codersdk/genericslice.go
77
export interface Foo<R extends any> {
8-
readonly Slice: (readonly R[])
9-
readonly TwoD: (readonly (readonly R[])[])
10-
}
8+
readonly Slice: Readonly<Array<R>>;
9+
readonly TwoD: Readonly<Array<Readonly<Array<R>>>>;
10+
}

site/e2e/helpers.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ export const sshIntoWorkspace = async (
241241
},
242242
write: cp.stdin.write.bind(cp.stdin),
243243
});
244-
// eslint-disable-next-line no-console -- Helpful for debugging
245-
cp.stderr.on("data", (data) => console.log(data.toString()));
244+
cp.stderr.on("data", (data) => console.info(data.toString()));
246245
cp.stdout.on("readable", (...args) => {
247246
proxyStream.emit("readable", ...args);
248247
if (cp.stdout.readableLength > 0) {
@@ -355,10 +354,8 @@ export const downloadCoderVersion = async (
355354
},
356355
},
357356
);
358-
// eslint-disable-next-line no-console -- Needed for debugging
359357
cp.stderr.on("data", (data) => console.error(data.toString()));
360-
// eslint-disable-next-line no-console -- Needed for debugging
361-
cp.stdout.on("data", (data) => console.log(data.toString()));
358+
cp.stdout.on("data", (data) => console.info(data.toString()));
362359
cp.on("close", (code) => {
363360
if (code === 0) {
364361
resolve();

site/e2e/reporter.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from "node:fs/promises";
22
import type { Writable } from "node:stream";
3-
/* eslint-disable no-console -- Logging is sort of the whole point here */
43
import type {
54
FullConfig,
65
FullResult,
@@ -170,5 +169,4 @@ const reportError = (error: TestError) => {
170169
}
171170
};
172171

173-
// eslint-disable-next-line no-unused-vars -- Playwright config uses it
174172
export default CoderReporter;

site/e2e/tests/webTerminal.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ test("web terminal", async ({ context, page }) => {
6262
);
6363
} catch (error) {
6464
const pageContent = await terminal.content();
65-
// eslint-disable-next-line no-console -- Let's see what is inside of xterm-rows
6665
console.error("Unable to find echoed text:", pageContent);
6766
throw error;
6867
}

0 commit comments

Comments
 (0)