Go代码的格式不一致?

Joh*_*ith 3 go gofmt

以下是一些示例代码:

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")
}
Run Code Online (Sandbox Code Playgroud)

以下是两种格式后的输出go fmt或按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")
}
Run Code Online (Sandbox Code Playgroud)

在空间os.MkdirAll()os.OpenFile()而他们在触及被删除os.Create()os.Stat().我希望格式化是相同的.

为什么会这样?

小智 5

请参阅:https://github.com/golang/go/issues/12720

gofmt使用二进制表达式周围的空格来表示绑定强度.根据嵌套级别,删除空格.

您也可以通过搜索"gofmt inconsistent spaces"轻松找到这些内容.另见问题#1206,#1848,#1861,#7880#11497.