Skip to content

Commit 4aba249

Browse files
committed
Ignore structs with anonymous fields (fixes #15)
1 parent 7ecf26e commit 4aba249

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

betteralign.go

+17
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ func run(pass *analysis.Pass) (interface{}, error) {
109109
nodeFilter := []ast.Node{
110110
(*ast.File)(nil),
111111
(*ast.StructType)(nil),
112+
(*ast.GenDecl)(nil),
112113
}
113114

114115
var aFile *ast.File
115116
var dFile *dst.File
117+
var strName string
116118

117119
applyFixesFset := make(map[string][]byte)
118120
testFset := make(map[string]bool)
@@ -142,11 +144,26 @@ func run(pass *analysis.Pass) (interface{}, error) {
142144

143145
var ok bool
144146
var s *ast.StructType
147+
var g *ast.GenDecl
148+
149+
if g, ok = node.(*ast.GenDecl); ok {
150+
if g.Tok == token.TYPE {
151+
decl := g.Specs[0].(*ast.TypeSpec)
152+
strName = decl.Name.Name
153+
}
154+
155+
return
156+
}
145157

146158
if s, ok = node.(*ast.StructType); !ok {
147159
return
148160
}
149161

162+
// ignore structs with anonymous fields
163+
if strName == "" {
164+
return
165+
}
166+
150167
if tv, ok := pass.TypesInfo.Types[s]; ok {
151168
betteralign(pass, s, tv.Type.(*types.Struct), dec, dFile, applyFixesFset, fn)
152169
}

0 commit comments

Comments
 (0)