@@ -33,7 +33,7 @@ func main() {
33
33
}
34
34
35
35
// Just cat the output to a file to capture it
36
- fmt .Println (codeBlocks .String ())
36
+ _ , _ = fmt .Println (codeBlocks .String ())
37
37
}
38
38
39
39
// TypescriptTypes holds all the code blocks created.
@@ -46,7 +46,7 @@ type TypescriptTypes struct {
46
46
// String just combines all the codeblocks.
47
47
func (t TypescriptTypes )String ()string {
48
48
var s strings.Builder
49
- s .WriteString ("// Code generated by 'make coder/scripts/apitypings/main.go'. DO NOT EDIT.\n \n " )
49
+ _ , _ = s .WriteString ("// Code generated by 'make coder/scripts/apitypings/main.go'. DO NOT EDIT.\n \n " )
50
50
51
51
sortedTypes := make ([]string ,0 ,len (t .Types ))
52
52
sortedEnums := make ([]string ,0 ,len (t .Types ))
@@ -63,14 +63,14 @@ func (t TypescriptTypes) String() string {
63
63
64
64
for _ ,k := range sortedTypes {
65
65
v := t .Types [k ]
66
- s .WriteString (v )
67
- s .WriteRune ('\n' )
66
+ _ , _ = s .WriteString (v )
67
+ _ , _ = s .WriteRune ('\n' )
68
68
}
69
69
70
70
for _ ,k := range sortedEnums {
71
71
v := t .Enums [k ]
72
- s .WriteString (v )
73
- s .WriteRune ('\n' )
72
+ _ , _ = s .WriteString (v )
73
+ _ , _ = s .WriteRune ('\n' )
74
74
}
75
75
76
76
return strings .TrimRight (s .String (),"\n " )
@@ -147,7 +147,6 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
147
147
ignoredTypes [strings .TrimSpace (s )]= struct {}{}
148
148
}
149
149
}
150
-
151
150
}
152
151
}
153
152
}
@@ -164,7 +163,7 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
164
163
continue
165
164
}
166
165
167
- switch obj .(type ) {
166
+ switch obj := obj .(type ) {
168
167
// All named types are type declarations
169
168
case * types.TypeName :
170
169
named ,ok := obj .Type ().(* types.Named )
@@ -175,7 +174,7 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
175
174
case * types.Struct :
176
175
// type <Name> struct
177
176
// Structs are obvious.
178
- st := obj .Type ().Underlying ().(* types.Struct )
177
+ st , _ := obj .Type ().Underlying ().(* types.Struct )
179
178
codeBlock ,err := g .buildStruct (obj ,st )
180
179
if err != nil {
181
180
return nil ,xerrors .Errorf ("generate %q: %w" ,obj .Name ())
@@ -188,14 +187,11 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
188
187
}
189
188
case * types.Var :
190
189
// TODO: Are any enums var declarations? This is also codersdk.Me.
191
- v := obj .(* types.Var )
192
- var _ = v
193
190
case * types.Const :
194
- c := obj .(* types.Const )
195
191
// We only care about named constant types, since they are enums
196
- if named ,ok := c .Type ().(* types.Named );ok {
192
+ if named ,ok := obj .Type ().(* types.Named );ok {
197
193
name := named .Obj ().Name ()
198
- enumConsts [name ]= append (enumConsts [name ],c )
194
+ enumConsts [name ]= append (enumConsts [name ],obj )
199
195
}
200
196
case * types.Func :
201
197
// Noop
@@ -214,8 +210,8 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
214
210
values = append (values ,elem .Val ().String ())
215
211
}
216
212
var s strings.Builder
217
- s .WriteString (g .posLine (v ))
218
- s .WriteString (fmt .Sprintf ("export type %s = %s\n " ,
213
+ _ , _ = s .WriteString (g .posLine (v ))
214
+ _ , _ = s .WriteString (fmt .Sprintf ("export type %s = %s\n " ,
219
215
name ,strings .Join (values ," | " ),
220
216
))
221
217
@@ -240,9 +236,9 @@ func (g *Generator) posLine(obj types.Object) string {
240
236
// buildStruct just prints the typescript def for a type.
241
237
func (g * Generator )buildStruct (obj types.Object ,st * types.Struct ) (string ,error ) {
242
238
var s strings.Builder
243
- s .WriteString (g .posLine (obj ))
239
+ _ , _ = s .WriteString (g .posLine (obj ))
244
240
245
- s .WriteString (fmt .Sprintf ("export interface %s {\n " ,obj .Name ()))
241
+ _ , _ = s .WriteString (fmt .Sprintf ("export interface %s {\n " ,obj .Name ()))
246
242
// For each field in the struct, we print 1 line of the typescript interface
247
243
for i := 0 ;i < st .NumFields ();i ++ {
248
244
field := st .Field (i )
@@ -273,15 +269,15 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
273
269
}
274
270
275
271
if tsType .Comment != "" {
276
- s .WriteString (fmt .Sprintf ("%s// %s\n " ,indent ,tsType .Comment ))
272
+ _ , _ = s .WriteString (fmt .Sprintf ("%s// %s\n " ,indent ,tsType .Comment ))
277
273
}
278
274
optional := ""
279
275
if tsType .Optional {
280
276
optional = "?"
281
277
}
282
- s .WriteString (fmt .Sprintf ("%sreadonly %s%s: %s\n " ,indent ,jsonName ,optional ,tsType .ValueType ))
278
+ _ , _ = s .WriteString (fmt .Sprintf ("%sreadonly %s%s: %s\n " ,indent ,jsonName ,optional ,tsType .ValueType ))
283
279
}
284
- s .WriteString ("}\n " )
280
+ _ , _ = s .WriteString ("}\n " )
285
281
return s .String (),nil
286
282
}
287
283
@@ -297,9 +293,9 @@ type TypescriptType struct {
297
293
// Eg:
298
294
//[]byte returns "string"
299
295
func (g * Generator )typescriptType (ty types.Type ) (TypescriptType ,error ) {
300
- switch ty .(type ) {
296
+ switch ty := ty .(type ) {
301
297
case * types.Basic :
302
- bs := ty .( * types. Basic )
298
+ bs := ty
303
299
// All basic literals (string, bool, int, etc).
304
300
switch {
305
301
case bs .Info ()& types .IsNumeric > 0 :
@@ -323,7 +319,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
323
319
return TypescriptType {ValueType :"any" ,Comment :"Embedded struct, please fix by naming it" },nil
324
320
case * types.Map :
325
321
// map[string][string] -> Record<string, string>
326
- m := ty .( * types. Map )
322
+ m := ty
327
323
keyType ,err := g .typescriptType (m .Key ())
328
324
if err != nil {
329
325
return TypescriptType {},xerrors .Errorf ("map key: %w" ,err )
@@ -342,7 +338,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
342
338
Elem () types.Type
343
339
}
344
340
345
- arr := ty .(hasElem )
341
+ arr , _ := ty .(hasElem )
346
342
switch {
347
343
// When type checking here, just use the string. You can cast it
348
344
// to a types.Basic and get the kind if you want too :shrug:
@@ -359,7 +355,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
359
355
return TypescriptType {ValueType :underlying .ValueType + "[]" ,Comment :underlying .Comment },nil
360
356
}
361
357
case * types.Named :
362
- n := ty .( * types. Named )
358
+ n := ty
363
359
// First see if the type is defined elsewhere. If it is, we can just
364
360
// put the name as it will be defined in the typescript codeblock
365
361
// we generate.
@@ -397,7 +393,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
397
393
return ts ,nil
398
394
case * types.Pointer :
399
395
// Dereference pointers.
400
- pt := ty .( * types. Pointer )
396
+ pt := ty
401
397
resp ,err := g .typescriptType (pt .Elem ())
402
398
if err != nil {
403
399
return TypescriptType {},xerrors .Errorf ("pointer: %w" ,err )