Search code examples
gotabsformattingvisual-studio-codenano

golang formatting on nano is messed up while on vscode it is okay. nano format is pushed to git


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?


Solution

  • 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.