Skip to content

Commit 32294ad

Browse files
committed
remove eslint cruft
1 parent fc3b2ff commit 32294ad

File tree

14 files changed

+1179
-1223
lines changed

14 files changed

+1179
-1223
lines changed

scripts/apitypings/main.go

+25-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,
@@ -965,15 +956,15 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
965956

966957
// If it's a struct, just use the name of the struct type
967958
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
959+
// External structs cannot be introspected, as we only parse the codersdk
960+
// package. You can handle your type manually in the switch list above,
961+
// otherwise `unknown` will be used. An easy way to fix this is to pull
962+
// your external type into codersdk, then it will be known by the
963+
// generator.
964+
return TypescriptType{
965+
AboveTypeLine: indentedComment(fmt.Sprintf("external type %q, using \"unknown\"", n.String())),
966+
ValueType: "unknown",
967+
}, nil
977968
}
978969

979970
// Defer to the underlying type.
@@ -1002,20 +993,16 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
1002993
// This field is 'interface{}'. We can't infer any type from 'interface{}'
1003994
// so just use "any" as the type.
1004995
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-
),
996+
AboveTypeLine: indentedComment("empty interface{} type, falling back to unknown"),
997+
ValueType: "unknown",
1011998
}, nil
1012999
}
10131000

10141001
// Interfaces are difficult to determine the JSON type, so just return
1015-
// an 'any'.
1002+
// an 'unknown'.
10161003
return TypescriptType{
1017-
ValueType: "any",
1018-
AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type."),
1004+
AboveTypeLine: indentedComment("interface type, falling back to unknown"),
1005+
ValueType: "unknown",
10191006
Optional: false,
10201007
}, nil
10211008
case *types.TypeParam:
@@ -1040,13 +1027,13 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
10401027
// If we don't have the type constraint defined somewhere in the package,
10411028
// then we have to resort to using any.
10421029
return TypescriptType{
1030+
AboveTypeLine: fmt.Sprintf("// %q is an external type, falling back to unknown", name),
10431031
GenericTypes: map[string]string{
1044-
ty.Obj().Name(): "any",
1032+
ty.Obj().Name(): "unknown",
10451033
},
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,
1034+
GenericValue: ty.Obj().Name(),
1035+
ValueType: "unknown",
1036+
Optional: false,
10501037
}, nil
10511038
}
10521039
// Include the builtin for this type to reference
@@ -1097,7 +1084,7 @@ func (Generator) isBuiltIn(name string) (bool, string) {
10971084
case "comparable":
10981085
// To be complete, we include "any". Kinda sucks :(
10991086
return true, "export type comparable = boolean | number | string | any"
1100-
case "any":
1087+
case "any", "unknown":
11011088
// This is supported in typescript, we don't need to write anything
11021089
return true, ""
11031090
default:

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)