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

huangapple go评论82阅读模式
英文:

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

问题

我安装了staticcheck,但它在我的Visual Studio Code中没有显示任何问题。

我已经配置了我的linter来使用staticcheck,并且我在互联网上到处查找。但它仍然不起作用。

这是我的settings.json文件的一部分:

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

我已经尝试在go.lintFlags中添加"-check=all"。我重新加载了Visual Studio Code,但它仍然不起作用。

当我查看官方网站时,他们提到了staticcheck.conf,但我不明白,因为我的系统上有多个名为staticcheck.conf的文件。

英文:

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.

答案1

得分: 4

你不需要使用"go.lintTool": "staticcheck",因为staticcheckvscode-go中的默认代码检查工具。

如果你启用了语言服务器,你需要显式地打开staticcheck,可以参考这里的说明,在gopls中设置"ui.diagnostic.staticcheck": true

作为替代方案,你可以设置golangci-lint作为你的代码检查工具,并在其中打开staticcheck

英文:

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.

huangapple
  • 本文由 发表于 2022年2月13日 22:10:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/71101439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定