Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to gofmt and goimports to use spaces instead of tabs #16256

Closed
pmalek opened this issue Jul 3, 2016 · 4 comments
Closed

Add option to gofmt and goimports to use spaces instead of tabs #16256

pmalek opened this issue Jul 3, 2016 · 4 comments

Comments

@pmalek
Copy link

pmalek commented Jul 3, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
go version go1.6.2 linux/amd64
  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/monkey/.gvm/pkgsets/go1.6.2/global"
GORACE=""
GOROOT="/home/monkey/.gvm/gos/go1.6.2"
GOTOOLDIR="/home/monkey/.gvm/gos/go1.6.2/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

I have (I presume many people do as well) goimport running on each save of my .go files in vim.
Normally I use spaces in all my projects but after using goimport or gofmt I receive my files tabified.

It would be handy if it was possible to run goimports or gofmt with flags like --usetab=true or something similar which would allow the alternate behavior of using spaces/tabs.

I believe it's fairly easy to implement in e.g. goimports - https://github.com/golang/tools/blob/master/cmd/goimports/goimports.go

Here is a connected issue in vim-go project fatih/vim-go#5

@dominikh
Copy link
Member

dominikh commented Jul 3, 2016

The point of gofmt is to have a single style that everybody uses. That includes the choice of using tabs over spaces. It doesn't have to be your – or anyone's – favourite style; just the style that is used by everyone.

gofmt used to have a flag to use spaces, but that flag was removed for precisely that reason. The output of the current gofmt is what your code should look like, no ifs or buts.

@pmalek
Copy link
Author

pmalek commented Jul 3, 2016

Ah.. I have forgotten about this one. You're right.

@pmalek pmalek closed this as completed Jul 3, 2016
@daggilli
Copy link

"The output of the current gofmt is what your code should look like, no ifs or buts."

My code should look exactly the way I want it. I don't want tabs. I want spaces. My boss wants spaces. My company wants spaces. There are no unbroken go formatting tools I can find.

@bradfitz
Copy link
Contributor

You can write your own gofmt replacement and use it within your company if you never want to share code with the wider community (the Go ecosystem expects gofmt'd code). It'd be around 100 lines of code:

https://github.com/golang/go/blob/master/src/go/format/format.go

I advise you not to.

@golang golang locked and limited conversation to collaborators Apr 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants