PiotrWolkowski
PiotrWolkowski

Reputation: 8782

Enable detailed options on golangci-lint in VSCode

I'm using golangci-lint. By default it disables golint linter. To add golint to default linters the command needs a -E golint flag:

golangci-lint run -E golint

From the command line that works fine.
But now I integrated golangci-lint with VSCode by adding this option to the settings:

"go.lintTool":"golangci-lint",

The default linters work fine but when I add a flag to enable golint it stops linting and doesn't return any output at all. To pass additional flag I followed the golangci-lint documentation and added go.lintFlags:

"go.lintFlags": [
  "--enable golint"
]

Note that I don't want to just run golint but rather to enable all default linters in golangci-lint and on top of that to use golint.

Upvotes: 7

Views: 13977

Answers (2)

Nate Finch
Nate Finch

Reputation: 273

add a .golangci.toml (or .yml or .json) to the root of the repo and set up the configuration via the file. You can also put that file in your $HOME directory if you want it to run across all repos. That's a lot better than trying to type in a bunch of CLI flags into your VSCode configuration. golangci-lint will read that file automatically and do the right thing. And that way if you run it from the command line, it'll use the same configuration.

Upvotes: 1

Oleg Butuzov
Oleg Butuzov

Reputation: 5395

I found it way easier to provide golangci-lint config.

"go.lintTool": "golangci-lint",
"go.lintFlags": [
    "-c",
    "~/.dotfiles/.golangci.yml",
    "--issues-exit-code=0"
],

And btw, you don't need to enable all default linters - thay are already enabled (see reference).

But if you want to run it via settings.json, you can define (as you did linter flags). For example next configuration

"go.lintTool": "golangci-lint",
"go.lintFlags": [
    "-E", "dogsled",
    "-E", "gochecknoglobals"
],

Applied to the

package main

func s(i int) (int, int, int, int, int) {
    return -1, -2, -3, -4, -5
}

func fpl() {
}

var i = 0

func main() {
    _, _, _, _, _ = s(i)
}

will result in:

...>Finished running tool: /Users/0_o/go/bin/golangci-lint run -E dogsled -E gochecknoglobals --print-issued-lines=false --out-format=colored-line-number --issues-exit-code=0
.../main.go:7:6 `fpl` is unused (deadcode)
.../main.go:13:2 declaration has 5 blank identifiers (dogsled)
.../main.go:10:5 `i` is a global variable (gochecknoglobals)

Upvotes: 6

Related Questions