Closed vanackere closed 8 years ago
Cannot reproduce. Latest versions of both commands produce the same output for me. Can you post what your output is (from goreturns
and goimports
)?
Both binaries use the same Go code to do gofmt
-level formatting, so it's unlikely they would be able to format differently.
I think what's likely happening here is one of your goreturns
or goimports
binaries is stale, built a long time ago. You can use binstale
and gostatus
tools to check.
I think if you do this, it'll fix your problem:
go get -u golang.org/x/tools/cmd/goimports
go get -u sourcegraph.com/sqs/goreturns
You are indeed right, I have a previous version of goreturns that do not have the same behaviour:
marvin:/tmp$ export GOPATH=$PWD
marvin:/tmp$ go get -u golang.org/x/tools/cmd/goimports
marvin:/tmp$ go get -u sourcegraph.com/sqs/goreturns
marvin:/tmp$ $HOME/bin/goreturns -d bug.go
diff bug.go gofmt/bug.go
--- /tmp/gofmt186851162 2016-01-25 09:02:02.766400770 +0100
+++ /tmp/gofmt056593649 2016-01-25 09:02:02.766400770 +0100
@@ -3,7 +3,7 @@
func g() {
f().
Scan(a,
- b)
+ b)
return
}
marvin:/tmp$ ./bin/goreturns -d bug.go
marvin:/tmp$ ls -l /home/vince/bin/goreturns
-rwxrwxr-x 1 vince vince 6984600 janv. 14 15:54 /home/vince/bin/goreturns
It turns out I had compiled this particular version of goreturns with go 1.6 (and goimports with go1.6 indeed exhibits the same formatting behaviour). I guess new the 1.6 behaviour results from a bug fix (seeing the different formatting in g() and h() in my sample using go 1.5). I'm closing this bug now. Thanks !
You're welcome!
Hi,
The following code in g() seems to be indented differently depending if I use goimports (same formatting as gofmt) or goreturns :
Note that there is no return value involved here... (I built this minimal sample from a much larger file where some coworkers and me were wondering why the formatting was always changing between our commits... turns out is was caused by us using different formatting tools !).