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 1 commit
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
Next Next commit
remove eslint cruft
  • Loading branch information
aslilac committed Aug 16, 2024
commit 32294ad58414892ac7c6159b02836c9d4aecc86a
63 changes: 25 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 @@ -965,15 +956,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 +993,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 +1027,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 +1084,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
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