]> Cypherpunks repositories - gostls13.git/commitdiff
go/ast: remove many blank lines in SortImports
authorSokolov Yura <funny.falcon@gmail.com>
Fri, 4 Dec 2015 17:54:24 +0000 (20:54 +0300)
committerRuss Cox <rsc@golang.org>
Fri, 4 Dec 2015 20:01:51 +0000 (20:01 +0000)
Currently only one blank line is checked to be removed.
Changing sort.Sort may lead to more blank lines.
Let's remove them all.

It fixes a bug found by https://golang.org/cl/15688

Change-Id: I682cc23ecd7b10d9b6feb160da040a155297f578
Reviewed-on: https://go-review.googlesource.com/17440
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/go/ast/import.go

index d2770d16cf862b8346832ee985a3bfb2624e051b..5c794c3e79821648e67b7dbabd0f97908c795a14 100644 (file)
@@ -43,8 +43,10 @@ func SortImports(fset *token.FileSet, f *File) {
                if len(d.Specs) > 0 {
                        lastSpec := d.Specs[len(d.Specs)-1]
                        lastLine := fset.Position(lastSpec.Pos()).Line
-                       if rParenLine := fset.Position(d.Rparen).Line; rParenLine > lastLine+1 {
-                               fset.File(d.Rparen).MergeLine(rParenLine - 1)
+                       rParenLine := fset.Position(d.Rparen).Line
+                       for rParenLine > lastLine+1 {
+                               rParenLine--
+                               fset.File(d.Rparen).MergeLine(rParenLine)
                        }
                }
        }