Skip to content

Commit 8dcb33c

Browse files
Cuong Manh Lecuonglm
authored andcommitted
Format struct using qualified package name
Fixes orijtech#13
1 parent e24c833 commit 8dcb33c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

structslop.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
6262
pass.Report(analysis.Diagnostic{
6363
Pos: n.Pos(),
6464
End: n.End(),
65-
Message: fmt.Sprintf("%v has size %d, could be %d, rearrange to %v for optimal size", styp, r.oldSize, r.newSize, r.suggestedStruct),
65+
Message: fmt.Sprintf("%s has size %d, could be %d, rearrange to %s for optimal size", formatStruct(styp), r.oldSize, r.newSize, formatStruct(r.suggestedStruct)),
6666
SuggestedFixes: nil,
6767
})
6868
})
@@ -122,3 +122,7 @@ func optimalStructArrangement(s *types.Struct) *types.Struct {
122122

123123
return types.NewStruct(fields, nil)
124124
}
125+
126+
func formatStruct(styp *types.Struct) string {
127+
return types.TypeString(styp, func(p *types.Package) string { return p.Name() })
128+
}

testdata/src/struct/p.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package p
1616

17+
import "net/http/httptest"
18+
1719
type s struct{}
1820

1921
type s1 struct {
@@ -38,3 +40,9 @@ type s4 struct { // want `struct{.+} has size 32, could be 20, rearrange to stru
3840
a3 [3]bool
3941
_ [0]func()
4042
}
43+
44+
type s5 struct { // want `struct{.+} has size 24, could be 20, rearrange to struct{y uint64; z \*httptest.Server; x uint32} for optimal size`
45+
x uint32
46+
y uint64
47+
z *httptest.Server
48+
}

0 commit comments

Comments
 (0)