Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 5 commits intomainfromupdate-apitypings
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsscripts/apitypings/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 willbe 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 DownExpand 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 DownExpand 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 deletionscripts/apitypings/main_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionscripts/apitypings/testdata/enums/enums.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
// From codersdk/enums.go
export type EnumSliceType =(readonlyEnum[])
export type EnumSliceType =Readonly<Array<Enum>>

// From codersdk/enums.go
export type Enum = "bar" | "baz" | "foo" | "qux"
Expand Down
10 changes: 5 additions & 5 deletionsscripts/apitypings/testdata/genericmap/genericmap.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsscripts/apitypings/testdata/generics/generics.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
// From codersdk/generics.go
exportinterfaceComplex<Cextendscomparable,SextendsSingle,TextendsCustom>{
readonlydynamic:Fields<C,boolean,string,S>
readonlyorder:FieldsDiffOrder<C,string,S,T>
readonlycomparable:C
readonlysingle:S
readonlystatic:Static
readonlydynamic:Fields<C,boolean,string,S>;
readonlyorder:FieldsDiffOrder<C,string,S,T>;
readonlycomparable:C;
readonlysingle:S;
readonlystatic:Static;
}

// From codersdk/generics.go
exportinterfaceDynamic<Aextendsany,SextendsSingle>{
readonlydynamic:Fields<boolean,A,string,S>
readonlycomparable:boolean
readonlydynamic:Fields<boolean,A,string,S>;
readonlycomparable:boolean;
}

// From codersdk/generics.go
exportinterfaceFields<Cextendscomparable,Aextendsany,TextendsCustom,SextendsSingle>{
readonlycomparable:C
readonlyany:A
readonlycustom:T
readonlyagain:T
readonlysingle_constraint:S
readonlycomparable:C;
readonlyany:A;
readonlycustom:T;
readonlyagain:T;
readonlysingle_constraint:S;
}

// From codersdk/generics.go
exportinterfaceFieldsDiffOrder<Aextendsany,Cextendscomparable,SextendsSingle,TextendsCustom>{
readonlyFields:Fields<C,A,T,S>
readonlyFields:Fields<C,A,T,S>;
}

// From codersdk/generics.go
exportinterfaceStatic{
readonlystatic:Fields<string,number,number,string>
readonlystatic:Fields<string,number,number,string>;
}

// From codersdk/generics.go
exporttypeCustom=string|boolean|number|(readonlystring[])|null
exporttypeCustom=string|boolean|number|Readonly<Array<string>>|null

// From codersdk/generics.go
exporttypeSingle=string

exporttypecomparable=boolean|number|string|any
exporttypecomparable=boolean|number|string|any
8 changes: 4 additions & 4 deletionsscripts/apitypings/testdata/genericslice/genericslice.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionssite/e2e/reporter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionsite/e2e/tests/webTerminal.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,6 @@ test("web terminal", async ({ context, page }) => {
);
}catch(error){
constpageContent=awaitterminal.content();
// eslint-disable-next-line no-console -- Let's see what is inside of xterm-rows
console.error("Unable to find echoed text:",pageContent);
throwerror;
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp