@@ -13,6 +13,7 @@ import (
13
13
"go/format"
14
14
"go/token"
15
15
"go/types"
16
+ "strings"
16
17
"unicode"
17
18
18
19
"golang.org/x/tools/go/analysis"
@@ -87,13 +88,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
87
88
}
88
89
89
90
var fillable bool
91
+ var fillableFields []string
90
92
for i := 0 ; i < fieldCount ; i ++ {
91
93
field := obj .Field (i )
92
94
// Ignore fields that are not accessible in the current package.
93
95
if field .Pkg () != nil && field .Pkg () != pass .Pkg && ! field .Exported () {
94
96
continue
95
97
}
96
98
fillable = true
99
+ fillableFields = append (fillableFields , fmt .Sprintf ("%s: %s" , field .Name (), field .Type ().String ()))
97
100
}
98
101
if ! fillable {
99
102
return
@@ -105,7 +108,21 @@ func run(pass *analysis.Pass) (interface{}, error) {
105
108
case * ast.SelectorExpr :
106
109
name = fmt .Sprintf ("%s.%s" , typ .X , typ .Sel .Name )
107
110
default :
108
- name = "anonymous struct"
111
+ totalFields := len (fillableFields )
112
+ maxLen := 20
113
+ // Find the index to cut off printing of fields.
114
+ var i , fieldLen int
115
+ for i = range fillableFields {
116
+ if fieldLen > maxLen {
117
+ break
118
+ }
119
+ fieldLen += len (fillableFields [i ])
120
+ }
121
+ fillableFields = fillableFields [:i ]
122
+ if i < totalFields {
123
+ fillableFields = append (fillableFields , "..." )
124
+ }
125
+ name = fmt .Sprintf ("anonymous struct { %s }" , strings .Join (fillableFields , ", " ))
109
126
}
110
127
pass .Report (analysis.Diagnostic {
111
128
Message : fmt .Sprintf ("Fill %s" , name ),
0 commit comments