From daeb0b4f538872a37787626816c47afcf71bfd2c Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 13 Aug 2018 17:25:49 -0700 Subject: [PATCH] go/printer: revert "make empty lines break table alignment" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts commit c116265eb3f2b1a8549e7ceef73b780439404030. The change, while addressing issue #26352, introduced another regression (#26930), which is worse. Reverting this change in favor of a better fix for the original issue. Updates #26352. Fixes #26930. Change-Id: I71ad12a8212992cce5c1e73907d1f7460f98d9e8 Reviewed-on: https://go-review.googlesource.com/129255 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí Reviewed-by: Brad Fitzpatrick --- src/go/printer/nodes.go | 17 ++++------------- src/go/printer/testdata/alignment.golden | 9 --------- src/go/printer/testdata/alignment.input | 9 --------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/go/printer/nodes.go b/src/go/printer/nodes.go index 3723f30e56..18f2371d24 100644 --- a/src/go/printer/nodes.go +++ b/src/go/printer/nodes.go @@ -221,22 +221,13 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp // If the previous line and the current line had single- // line-expressions and the key sizes are small or the // ratio between the current key and the geometric mean - // does not exceed a threshold, align columns and do not use - // formfeed. - // If the previous line was an empty line, break the alignment. - // (The text/tabwriter will break alignment after an empty line - // even if we don't do anything here, but we can't see that; yet - // we need to reset the variables used in the geomean - // computation after an alignment break. Do it explicitly - // instead so we're aware of the break. Was issue #26352.) + // if the previous key sizes does not exceed a threshold, + // align columns and do not use formfeed. if prevSize > 0 && size > 0 { const smallSize = 40 - switch { - case prevLine+1 < line: - useFF = true - case count == 0, prevSize <= smallSize && size <= smallSize: + if count == 0 || prevSize <= smallSize && size <= smallSize { useFF = false - default: + } else { const r = 2.5 // threshold geomean := math.Exp(lnsum / float64(count)) // count > 0 ratio := float64(size) / geomean diff --git a/src/go/printer/testdata/alignment.golden b/src/go/printer/testdata/alignment.golden index 302b32e766..c65defe6ae 100644 --- a/src/go/printer/testdata/alignment.golden +++ b/src/go/printer/testdata/alignment.golden @@ -128,12 +128,3 @@ func main() { abcdefghijklmnopqrstuvwxyz: "foo", } } - -// ---------------------------------------------------------------------------- -// Examples from issue #26352. -var _ = map[int]string{ - 1: "", - - 12345678901234567890123456789: "", - 12345678901234567890123456789012345678: "", -} diff --git a/src/go/printer/testdata/alignment.input b/src/go/printer/testdata/alignment.input index 83361cc7c1..9b0aae6bec 100644 --- a/src/go/printer/testdata/alignment.input +++ b/src/go/printer/testdata/alignment.input @@ -128,12 +128,3 @@ func main() { abcdefghijklmnopqrstuvwxyz: "foo", } } - -// ---------------------------------------------------------------------------- -// Examples from issue #26352. -var _ = map[int]string{ - 1: "", - - 12345678901234567890123456789: "", - 12345678901234567890123456789012345678: "", -} -- 2.48.1