Skip to content

Commit

Permalink
go/analysis/passes/fieldalignment: filter comments from suggested fix
Browse files Browse the repository at this point in the history
go/ast has problem with comments from its design, for now, best way is
to get rid of the comments.

See golang/go#20744 for general problem.

Updates golang/go#43233

Change-Id: I7c29dc9d0573f5f894859cd8b24e010a777ebba2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278872
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
  • Loading branch information
Cuong Manh Le authored and stamblerre committed Dec 17, 2020
1 parent 4b31ac3 commit 5b43ef9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/analysis/passes/fieldalignment/fieldalignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func fieldalignment(pass *analysis.Pass, node *ast.StructType, typ *types.Struct
// TODO: Preserve multi-named fields instead of flattening.
var flat []*ast.Field
for _, f := range node.Fields.List {
// TODO: Preserve comment, for now get rid of them.
// See https://github.com/golang/go/issues/20744
f.Comment = nil
if len(f.Names) <= 1 {
flat = append(flat, f)
continue
Expand Down
8 changes: 8 additions & 0 deletions go/analysis/passes/fieldalignment/testdata/src/a/a_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ type MultiField struct { // want "struct of size 40 could be 24"
a3 [3]bool
_ [0]func()
}

type Issue43233 struct { // want "struct with 88 pointer bytes could be 80"
AllowedEvents []*string // allowed events
BlockedEvents []*string // blocked events
APIVersion string `mapstructure:"api_version"`
BaseURL string `mapstructure:"base_url"`
AccessToken string `mapstructure:"access_token"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ type MultiField struct {
a3 [3]bool
b bool
}

type Issue43233 struct {
APIVersion string `mapstructure:"api_version"`
BaseURL string `mapstructure:"base_url"`
AccessToken string `mapstructure:"access_token"`
AllowedEvents []*string
BlockedEvents []*string
}

0 comments on commit 5b43ef9

Please sign in to comment.