Skip to content

Commit 520e8bc

Browse files
committed
fix
1 parent 39fe255 commit 520e8bc

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

scripts/apitypings/main.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,31 @@ func run() error {
4545
astFiles = append(astFiles, astFile)
4646
}
4747

48+
// TypeSpec case for structs and type alias
4849
loopSpecs(astFiles, func(spec ast.Spec) {
4950
pos := fset.Position(spec.Pos())
50-
switch s := spec.(type) {
51-
// TypeSpec case for structs and type alias
52-
case *ast.TypeSpec:
53-
out, err := handleTypeSpec(s, pos, enums)
54-
if err != nil {
55-
break
56-
}
57-
58-
_, _ = fmt.Printf(out)
51+
s, ok := spec.(*ast.TypeSpec)
52+
if !ok {
53+
return
5954
}
55+
out, err := handleTypeSpec(s, pos, enums)
56+
if err != nil {
57+
return
58+
}
59+
60+
_, _ = fmt.Printf(out)
6061
})
6162

63+
// ValueSpec case for loading type alias values into the enum map
6264
loopSpecs(astFiles, func(spec ast.Spec) {
63-
switch s := spec.(type) {
64-
// ValueSpec case for const "enums"
65-
case *ast.ValueSpec:
66-
handleValueSpec(s, enums)
65+
s, ok := spec.(*ast.ValueSpec)
66+
if !ok {
67+
return
6768
}
69+
handleValueSpec(s, enums)
6870
})
6971

72+
// write each type alias declaration with possible values
7073
for _, v := range enums {
7174
_, _ = fmt.Printf("%s\n", v)
7275
}

0 commit comments

Comments
 (0)