0

I am new with golang and we just had our first git commit of it and to our surprise the indentations were different.

On vscode my code looks like this : The indentations/tabs are well formatted.

vscode-golang-formatting

and on nano and github it got broken.

nano-golang-formatting

I found an answer related, a tool here that formats the tabs and spaces but do I really have to invoke go fmt every time I have to git?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

1 Answers1

5

do I really have to invoke go fmt every time I have to git?

You should rather invoke go fmt every time you are saving your file locally with your IDE.
That way, and add, commit and push will be done with a consistent format.

For VSCode, see Format on save, the the vscode-go extension.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have installed the [vscode-go-extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go) you recommended. The indentations are well formatted now. I checked thru `nano`. Also to add, whenever I hit save on vscode, it behaves as if I invoke `go build` and checks if I was using the import if not, it automatically removes it. Awesome. Marking this as solved. – Karen Irene Cano May 26 '18 at 03:25