Auto Formatiting Not Working and inserting Tabs Instead of Spaces

Answered

I have been using intelliJ Ultimate for many many years with no real issues until now. I am on the latest intelliJ Ultimate using the Ubuntu snap:

IntelliJ IDEA 2023.2.1 (Ultimate Edition)
Build #IU-232.9559.62, built on August 22, 2023
Licensed to XXX Company Inc
Expiration date: September 15, 2023
Runtime version: 17.0.8+7-b1000.8 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.2.0-32-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
Registry:
   debugger.new.tool.window.layout=true
   ide.experimental.ui=true
Non-Bundled Plugins:
   com.samvtran.plugins.macosforallkeymap (2.0.0)
   name.kropp.intellij.makefile (232.8660.88)
   org.jetbrains.plugins.go (232.9559.65)
   com.jetbrains.packagesearch.intellij-plugin (232.9559.10)
   Pythonid (232.9559.62)
   com.carbonblack.intellij.rpmspec (2.2.0)
Kotlin: 232-1.9.0-IJ9559.62
Current Desktop: ubuntu:GNOME

 

For go files I am noticing two very serious/annoying issues:
1) Auto format stopped working. When adding spaces or newlines or other such issues and hitting save for example did nothing. In fact it started turning all my spaces into tabs!
2) Tabs are being used instead of spaces even “use tab character” has always been unchecked in Code Style > Go.

I did notice that uninstalling Golang plugin and restarting seemed to help for a bit, but the issue quickly came back in a few days. Invalidating all the caches and restarting did not help.

Please let me know what additional information I can provide.

 

1
4 comments

Looks like gofmt defaults to tabs instead of spaces. So rather than fighting things go with that. My bad!

0

Hi,

You can turn off Run gofmt on code reformat in Preferences | Editor | Code Style | Go | Other and continue to use tabs instead of spaces (but keep in mind that CI/CD tools or any other ones may run gofmt under the hood).

0

I have the same issue and it's really annoying. All new .go files I add become tab formatted even everywhere in settings I have selected to use spaces. It happens on file save for me. So after code reformat I see that GoLand started to use spaces, but then after file is saved, all spaces become tabs again and I can't save it with using spaces to indents.. I tried to remove all actions On Save and it doesn't help. 
The only thing that helped was to disable checkbox On Reformat Code option under Run gofmt section in Code Style → Go → Other 
However I'm not sure that I really want to disable running gofmt.
Please fix, it's very annoying.

0

Hi Nikolay Pohodnya, it's a go fmt feature. It automatically changes spaces to tabs indentation and there is no way to fix it somehow on GoLand side. The idea of that approach is to have a unified way of formatting for all Go projects.

0

Please sign in to leave a comment.