Skip to content

Commit

Permalink
Fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jun 28, 2024
1 parent 242f88c commit c9119d6
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions types/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,24 @@ func (t *Type) Format(s fmt.State, v rune) {
name = pkg + "." + name
}

writeString := func(str string) {
_, _ = s.Write([]byte(str))
}

if t.Opaque() {
if name == "" {
name = fmt.Sprintf("<anon %s>", t.Kind())
}
if t.typ.Kind == coroutinev1.Kind_KIND_POINTER {
name = "*" + name
}
s.Write([]byte(name))
writeString(name)
return
}

verbose := s.Flag('+') || s.Flag('#')
if name != "" && !verbose {
s.Write([]byte(name))
writeString(name)
return
}

Expand Down Expand Up @@ -386,7 +390,7 @@ func (t *Type) Format(s fmt.State, v rune) {
default:
result = primitiveKind
}
s.Write([]byte(result))
writeString(result)
return
}

Expand All @@ -412,82 +416,82 @@ func (t *Type) Format(s fmt.State, v rune) {
if name != "" {
elemPrefix = fmt.Sprintf("(%s=%s", name, elemPrefix)
}
s.Write([]byte(elemPrefix))
writeString(elemPrefix)
t.Elem().Format(withoutFlags{s}, v)
if name != "" {
s.Write([]byte(")"))
writeString(")")
}
return
}

if name != "" {
s.Write([]byte(fmt.Sprintf("(%s=", name)))
writeString(fmt.Sprintf("(%s=", name))
}
switch t.typ.Kind {
case coroutinev1.Kind_KIND_FUNC:
s.Write([]byte("func("))
writeString("func(")
paramCount := t.NumParam()
for i := 0; i < paramCount; i++ {
if i > 0 {
s.Write([]byte(", "))
writeString(", ")
}
if i == paramCount-1 && t.Variadic() {
s.Write([]byte("..."))
writeString("...")
}
t.Param(i).Format(withoutFlags{s}, v)
}
s.Write([]byte(")"))
writeString(")")
n := t.NumResult()
if n > 0 {
s.Write([]byte(" "))
writeString(" ")
}
if n > 1 {
s.Write([]byte("("))
writeString("(")
}
for i := 0; i < n; i++ {
if i > 0 {
s.Write([]byte(", "))
writeString(", ")
}
t.Result(i).Format(withoutFlags{s}, v)
}
if n > 1 {
s.Write([]byte(")"))
writeString(")")
}
if name != "" {
s.Write([]byte(")"))
writeString(")")
}

case coroutinev1.Kind_KIND_MAP:
s.Write([]byte("map["))
writeString("map[")
t.Key().Format(withoutFlags{s}, v)
s.Write([]byte("]"))
writeString("]")
t.Elem().Format(withoutFlags{s}, v)

case coroutinev1.Kind_KIND_STRUCT:
n := t.NumField()
if n == 0 {
s.Write([]byte("struct{}"))
writeString("struct{}")
} else {
s.Write([]byte("struct{ "))
writeString("struct{ ")
for i := 0; i < n; i++ {
if i > 0 {
s.Write([]byte("; "))
writeString("; ")
}
f := t.Field(i)
if !f.Anonymous() {
s.Write([]byte(f.Name()))
s.Write([]byte(" "))
writeString(f.Name())
writeString(" ")
}
f.Type().Format(withoutFlags{State: s}, v)
}
s.Write([]byte(" }"))
writeString(" }")
}

default:
s.Write([]byte("invalid"))
writeString("invalid")
}
if name != "" {
s.Write([]byte(")"))
writeString(")")
}
}

Expand Down

0 comments on commit c9119d6

Please sign in to comment.