How can I configure the 'staticcheck' linter in Visual Studio Code?

Issue

I installed staticcheck, but it doesn’t tell me any problems in my Visual Studio Code.

I configured my linter to use staticcheck and I looked everywhere on the Internet. It still doesn’t work.

Here is a part of my settings.json file:

{
  "go.formatTool": "goimports",
  "go.useLanguageServer": true,
  "go.lintTool": "staticcheck",
  "go.lintFlags": [],
  "go.testFlags": ["-v"],
  "go.toolsManagement.autoUpdate": true,
  "editor.codeActionsOnSave": { "source.fixAll.eslint": true }
}

I already tried to add "-check=all" on the go.lintFlags. I reloaded my Visual Studio Code, but it still doesn’t work.

When I checked the official website they talk about staticcheck.conf, but I don’t get it since there are multiple files named staticcheck.conf on my system.

Solution

You don’t need "go.lintTool": "staticcheck", because, this is (staticcheck) default linting tool in vscode-go.

If you have language serve enabled, you need to turn staticcheck explicitly with

"gopls": { "ui.diagnostic.staticcheck": true }.

As alternative, you can set up golangci-lint as your linter and turn staticcheck in it.

Answered By – Oleg Butuzov

Answer Checked By – Timothy Miller (GoLangFix Admin)

Leave a Reply

Your email address will not be published.