When I run go fmt ./... under the root directory of the project in my vscode I got different formatting results on different OS:
Windows
import (
"github.com/abc"
"gotest.tools/assert"
"testing"
)
MacOS
import (
"testing"
"github.com/abc"
"gotest.tools/assert"
)
Is this the expected behaviour for gofmt in different OS? If so, how do I config the code formatting rules in vscode to make it consistent?
Edit: I am using the same version of Golang on both OS.
It is very likely you have different versions of gofmt on different platforms. Another option - different set of commands.
You can try to run the command like this:
It should print details of
gofmtutility calls. You can diff outputs from different platforms.Based on my past experience VSCode didn't seem reliable and I had to switch to GoLand.