diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2013-09-06 16:25:15 -0400 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2013-09-06 16:25:15 -0400 |
commit | d8cb74b801eb363e9e9d0079593d308314169d8d (patch) | |
tree | 1b26849d2cfddb747c5f564348a70b200f43df74 /src/cmd/gofmt | |
parent | ea43cd6badd50754b67b334fa491c9997315256b (diff) | |
download | go-d8cb74b801eb363e9e9d0079593d308314169d8d.tar.gz |
cmd/gofmt: sort more, remove some duplicate imports
* Sort imports by import path, then import name, then comment. Currently, gofmt sorts only by import path.
* If two imports have the same import path and import name, and one of them has no comment, remove the import with no comment. (See the discussion at issue 4414.)
Based on @rsc's https://codereview.appspot.com/7231070/
Fixes issue 4414.
R=gri, rsc
CC=golang-dev
https://codereview.appspot.com/12837044
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/gofmt')
-rw-r--r-- | src/cmd/gofmt/testdata/import.golden | 18 | ||||
-rw-r--r-- | src/cmd/gofmt/testdata/import.input | 23 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/cmd/gofmt/testdata/import.golden b/src/cmd/gofmt/testdata/import.golden index e8ee44988..51d7be79d 100644 --- a/src/cmd/gofmt/testdata/import.golden +++ b/src/cmd/gofmt/testdata/import.golden @@ -106,3 +106,21 @@ import ( "log" // for Fatal "math" ) + +// Test deduping and extended sorting +import ( + a "A" // aA + b "A" // bA1 + b "A" // bA2 + "B" // B + . "B" // .B + _ "B" // _b + "C" + a "D" // aD +) + +import ( + "dedup_by_group" + + "dedup_by_group" +) diff --git a/src/cmd/gofmt/testdata/import.input b/src/cmd/gofmt/testdata/import.input index cc36c3e01..9a4b09dbf 100644 --- a/src/cmd/gofmt/testdata/import.input +++ b/src/cmd/gofmt/testdata/import.input @@ -106,3 +106,26 @@ import ( "errors" "io" // for Reader ) + +// Test deduping and extended sorting +import ( + "B" // B + a "A" // aA + b "A" // bA2 + b "A" // bA1 + . "B" // .B + . "B" + "C" + "C" + "C" + a "D" // aD + "B" + _ "B" // _b +) + +import ( + "dedup_by_group" + "dedup_by_group" + + "dedup_by_group" +) |