Golangci-lint: vs-code lintflags

Created on 7 Sep 2018  路  5Comments  路  Source: golangci/golangci-lint

Hello,

It seems that if we want to add flags using vscode:

        "go.lintTool": "golangci-lint",
        "go.lintFlags": ["--enable-all"],

The linter doesn't work anymore, I'm guessing it has to do with the command run. Do you have a workaround to enable more linter in vs-code ? Could we use a config file ? If yes is it per package/project ?

go version
go version go1.9 windows/amd64

golangci-lint version v1.10.2

Thank you !

Most helpful comment

@karim

  1. about diff tool - I made the issue https://github.com/golangci/golangci-lint/issues/362, thank you
  2. it's not about golangci-lint, it's about how OS runs programs. When you type golangci-lint run --disable goimports in a shell it executes system call with arguments ["golangci-lint", "run", "--disable", "goimports"]. Pay attention that shell splits source line by spaces. And when an editor is configurated in such format it means that you need to write it without spaces.

All 5 comments

Hi!

I use following settings:

    "go.lintTool":"golangci-lint",
    "go.lintFlags": [
        "--fast"
    ],

And it works ok. Configuration (enabled/disabled linters) is automatically found in a `.golangci.yml file in repo by golangci-lint. You can also use such config file, it's convenient.

@Kuqd Showing the output window (Ctrl+Shift+U or View > Output) in Visual Studo Code gives this error:

Error while running tool: C:\Go\bin\golangci-lint.exe run --enable-all --print-issued-lines=false
level=warning msg="[runner] Can't run linter goimports: error computing diff: exec: \"diff\": executable file not found in %PATH%"
level=warning msg="[runner] Can't run linter gofmt: error computing diff: exec: \"diff\": executable file not found in %PATH%"

Either install this missing tool, or disable both goimports and gofmt to make it work.


Which brings me to my issue. I tried to disable these linters but I think I hit a bug.

On Windows, golangci-lint is giving inconsistent results when using the enable/disable flags.

  1. "go.lintFlags": ["--enable-all", "--disable goimports", "--disable gofmt"] returns:

    Error while running tool: C:\Go\bin\golangci-lint.exe run --enable-all --disable goimports --disable gofmt --print-issued-lines=false
    level=error msg="Can't get config for command line: can't parse args: unknown flag: --disable goimports"

  2. "go.lintFlags": ["--enable-all", "-D goimports", "-D gofmt"], returns:

    Error while running tool: C:\Go\bin\golangci-lint.exe run --enable-all -D goimports -D gofmt --print-issued-lines=false
    level=error msg="Running error: no such linter \" goimports\""

  3. "go.lintFlags": ["--enable-all", "-Dgoimports", "-Dgofmt"] (removing the space between -D and the linter name) works!

  4. "go.lintFlags": ["--enable-all", "--disablegoimports", "--disablegofmt"] (removing the space between --disable and the linter name) does not work (same as 1.), and retuns:

    Error while running tool: C:\Go\bin\golangci-lint.exe run --enable-all --disablegoimports --disablegofmt --print-issued-lines=false
    level=error msg="Can't get config for command line: can't parse args: unknown flag: --disablegoimports"

A table for better view..

|#|Flag|Error|
|:-:|:--|:--|
|1|--disable linter|Can't get config for command line: can't parse args: unknown flag: --disable goimports|
|2|-D linter|Running error: no such linter \" goimports\"|
|3|-Dlinter||
|4|--disablelinter|Can't get config for command line: can't parse args: unknown flag: --disablegoimports|

Only # 3 works even though all documentations use either # 1 or # 2.

Go: 1.11.4
VS Code: 1.30.1
golangci-lint: latest I think since vs code installed it (golangci-lint --version doesn't work)

I used config file as mentioned by @jirfag , I'm ok to close that issue if you'd like.

Thanks !

@karim

  1. about diff tool - I made the issue https://github.com/golangci/golangci-lint/issues/362, thank you
  2. it's not about golangci-lint, it's about how OS runs programs. When you type golangci-lint run --disable goimports in a shell it executes system call with arguments ["golangci-lint", "run", "--disable", "goimports"]. Pay attention that shell splits source line by spaces. And when an editor is configurated in such format it means that you need to write it without spaces.

Thanks @jirfag for your explanation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kipply picture kipply  路  4Comments

alessio picture alessio  路  4Comments

bacongobbler picture bacongobbler  路  4Comments

liubog2008 picture liubog2008  路  3Comments

jsm picture jsm  路  5Comments