Dynamic vscode settings for linting config?

72 Views Asked by At

At work, we have a shared golangci configuration that lives in a github repo, github.com/github/go-linter.

I'm trying to figure out how best to share that configuration across many go repos. I've heard that other languages use their package managers to handle pinning a version of the linting config, and I thought that sounded like a good idea. I can get that to work, mostly.

In the go project, we add a

import _ "github.com/github/go-linter"

Which then pins a version of the go-linter code in our go.mod.

I can then call golangci-lint using the config file in that go-linter module by using this command from the terminal:

golangci-lint run -v -c $(go list -f '{{.Dir}}' -m github.com/github/go-linter)/.golangci.toml

Cool. Now I can run that locally and in CI, and always use the same pinned version of the config file referenced by the project's go.mod file.

However, there doesn't immediately seem to be a way to get VSCode to use the same setting for it's lint-on-save functionality. You can't set this in your settings.json:

"go.lintFlags": [
    "-c",
    "$(go list -f '{{.Dir}}' -m github.com/github/go-linter)/.golangci.toml"
  ],

It doesn't work (and probably shouldn't.... I don't think we want our settings file to be able to run arbitrary bash commands).

But I'm not sure how to solve this conundrum - using the correct linter config in vscode is super important to avoid having to wait for CI to find linting errors.

Any suggestions would be welcome. Ideally, I'd like to use go modules to pin the config version, but I'd consider other solutions (aside from git submodules... I know someone is going to suggest it, and just... no).

0

There are 0 best solutions below