Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vs-code lintflags #222

Closed
cyriltovena opened this issue Sep 7, 2018 · 5 comments
Closed

vs-code lintflags #222

cyriltovena opened this issue Sep 7, 2018 · 5 comments

Comments

@cyriltovena
Copy link

cyriltovena commented Sep 7, 2018

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 !

@jirfag
Copy link
Member

jirfag commented Oct 28, 2018

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.

@karim
Copy link

karim commented Dec 27, 2018

@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)

@cyriltovena
Copy link
Author

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

Thanks !

@jirfag
Copy link
Member

jirfag commented Jan 20, 2019

@karim

  1. about diff tool - I made the issue Maybe inline diff tool into golangci-lint #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.

@jirfag jirfag closed this as completed Jan 20, 2019
@karim
Copy link

karim commented Jan 21, 2019

Thanks @jirfag for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants