The Go extension runs the below on each file save by default. You can turn them off in settings.
go.buildOnSave
setting)go.lintOnSave
setting)go.vetOnSave
setting)"[go]": { "editor.formatOnSave": false }
The below can be enabled to run on file save by turning them on in settings
On each file save, the package that the file belongs to is built to find any compile errors. If the file is a test file then go test -i -c -o
is used instead of go build -i -o
The binary generated by the build process is written to a temporary location as the purpose here is to only find compile errors and not to provide a binary/executable.
The below settings control the build on save feature
-tags
flag-i
flag is passed to speed up the build process. If you don't want the -i
flag to be used, set go.installDependenciesWhenBuilding
to false
.A linter is a tool giving coding style feedback and suggestions. By default this extension uses the official golint as a linter.
You can change the default linter and use the more advanced Go Meta Linter by setting go.lintTool
to “gometalinter” in your settings.
Go meta linter uses a collection of various linters which will be installed for you by the extension.
Some of the very useful linter tools:
If you want to run only specific linters (some linters are slow), you can modify your configuration to specify them:
"go.lintFlags": ["--disable-all", "--enable=errcheck"],
Alternatively, you can use megacheck which may have significantly better performance than gometalinter
, while only supporting a subset of the tools.
To disable lint on save turn off go.lintOnSave
If you have Auto Save feature enabled, then you might want to disable the format on save feature so that the code doesnt keep changing under you. You can do this by adding the below in your settings:
"[go]": { "editor.formatOnSave": false }
By default, goreturns
is the tool used for formatting. You can choose goimports
or gofmt
by changing the go.formatTool
setting
If you see your unused imports disappearing or unimported packages getting added automatically, thats the goreturns
tool doing the magic behind the scenes.