vscodeでGoのコードフォーマットに "go.formatTool": "goimports"
を指定していて、-local
オプションが効かなかったので調べた。
-local
は、-local "github.com/my/module"
のように指定すると、importをサードパーティのモジュールと自身のモジュールでグループ分けしてくれるオプション
import (
"fmt"
"os"
"github.com/other/module1"
"github.com/other/module2"
"github.com/my/module/client"
"github.com/my/module/service"
)
go.formatFlags
https://github.com/golang/vscode-go/wiki/settings#goformatflags
これは効かない
Not applicable when using the language server.
{
"go.formatFlags": [
"-local",
"github.com/my/module"
],
}
gopls."formatting.local"
こちらが正しい
{
"gopls": {
"formatting.local": "github.com/my/module"
},
}