Go代码格式不一致?

Inconsistent formatting of Go code?

下面是一些示例代码:

func main() {
    os.MkdirAll(outDir + id, 0755)
    os.Create(outDir + id + "/txt")
    os.OpenFile(outDir + id + "/" + ".tmp", os.OWRONLY|os_APPEND)
    os.Stat(outDir + id + "/.tmp")
}

以下是使用 go fmt 或在 Go Playground 上按 Format 格式化后的输出:

func main() {
    os.MkdirAll(outDir+id, 0755)
    os.Create(outDir + id + "/txt")
    os.OpenFile(outDir+id+"/"+".tmp", os.OWRONLY|os_APPEND)
    os.Stat(outDir + id + "/.tmp")
}

os.MkdirAll()os.OpenFile() 中的空格被删除,而 os.Create()os.Stat() 中的空格未被修改。我希望格式相同。

为什么会这样?

参见:https://github.com/golang/go/issues/12720

gofmt uses spaces around binary expressions to express binding strength. Depending on nesting level, spaces are removed.

You could also find these easily by searching for "gofmt inconsistent spaces". See also issue #1206, #1848, #1861, #7880, and #11497.