Skip to content

Commit

Permalink
Ignore structs with anonymous fields (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorunic committed Jul 22, 2024
1 parent 7ecf26e commit 4aba249
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions betteralign.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ func run(pass *analysis.Pass) (interface{}, error) {
nodeFilter := []ast.Node{
(*ast.File)(nil),
(*ast.StructType)(nil),
(*ast.GenDecl)(nil),
}

var aFile *ast.File
var dFile *dst.File
var strName string

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

var ok bool
var s *ast.StructType
var g *ast.GenDecl

if g, ok = node.(*ast.GenDecl); ok {
if g.Tok == token.TYPE {
decl := g.Specs[0].(*ast.TypeSpec)
strName = decl.Name.Name
}

return
}

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

// ignore structs with anonymous fields
if strName == "" {
return
}

if tv, ok := pass.TypesInfo.Types[s]; ok {
betteralign(pass, s, tv.Type.(*types.Struct), dec, dFile, applyFixesFset, fn)
}
Expand Down

0 comments on commit 4aba249

Please sign in to comment.