Skip to content

Commit 4922717

Browse files
leitzlerstamblerre
authored andcommitted
go/analysis/passes/fieldalignment: delete doc style comments in fix
CL 278872 fixed the fact that field comments messed up the suggested edits by removing comments entirely. This change also remove documentation style comments since they also produce broken suggestions in the same way. Change-Id: I18d9c42fbf1453dcd5019b2a4aa3f4be4a58f7c7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/284732 Trust: Rebecca Stambler <rstambler@golang.org> Trust: Pontus Leitzler <leitzler@gmail.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
1 parent 917f61d commit 4922717

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

go/analysis/passes/fieldalignment/fieldalignment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func fieldalignment(pass *analysis.Pass, node *ast.StructType, typ *types.Struct
7979
// TODO: Preserve comment, for now get rid of them.
8080
// See https://github.com/golang/go/issues/20744
8181
f.Comment = nil
82+
f.Doc = nil
8283
if len(f.Names) <= 1 {
8384
flat = append(flat, f)
8485
continue

go/analysis/passes/fieldalignment/testdata/src/a/a.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ type NoNameBad struct { // want "struct of size 20 could be 16"
3535
y int32
3636
z byte
3737
}
38+
39+
type WithComments struct { // want "struct of size 8 could be 4"
40+
// doc style comment
41+
a uint32 // field a comment
42+
b [0]byte // field b comment
43+
// other doc style comment
44+
45+
// and a last comment
46+
}

go/analysis/passes/fieldalignment/testdata/src/a/a.go.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ type NoNameBad struct {
3535
x byte
3636
z byte
3737
}
38+
39+
type WithComments struct {
40+
b [0]byte
41+
a uint32
42+
}

0 commit comments

Comments
 (0)