在VSCode中更严格地检查Golang代码的规范性。

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

Stricter lint of Golang in VSCode

问题

我正在使用VSCode进行我的Golang项目,使用默认的lint设置,但是我找不到一种方法来进行严格的lint检查,以便在代码中标出问题,使我能够严格遵守官方的Go准则,例如:

  • 以函数名开头的函数注释,
  • 变量只使用驼峰命名法,
  • 包名只使用蛇形命名法,
  • 等等...

如何在VSCode中实现严格的lint检查行为?

英文:

I'm using VSCode for my Golang projects with the default lint settings, and I can't find a way to have a strict lint of my Go files, underlining the problems in the code, that would allow me to abide strictly to official Go guidelines, such as:

  • Starting comments of functions with the function name,
  • Using only camel case in variables,
  • Using only snake case in package name,
  • etc...

How to get strict linting behaviour in VSCode?

答案1

得分: 2

是的,你可以。staticcheck 是 VSCode 的默认 Go 语言的 linter。

Staticcheck 的默认配置会忽略某些规则。你可以通过自己的 staticcheck.conf 文件中添加 checks=["all"] 条目来重新启用所有规则。

# https://staticcheck.io/docs/configuration

# checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
checks = ["all"]
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
	"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
	"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
	"SMTP", "SQL", "SSH", "TCP", "TLS", "TTL",
	"UDP", "UI", "GID", "UID", "UUID", "URI",
	"URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
	"XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
dot_import_whitelist = []
http_status_code_whitelist = ["200", "400", "404", "500"]

英文:

Yes you can. staticcheck is VSCode's default go linter.

Staticcheck's default configuration ignores certain rules. You can opt back in to all rules with your own staticcheck.conf with a checks=["all"] entry.

# https://staticcheck.io/docs/configuration

# checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
checks = ["all"]
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
	"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
	"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
	"SMTP", "SQL", "SSH", "TCP", "TLS", "TTL",
	"UDP", "UI", "GID", "UID", "UUID", "URI",
	"URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
	"XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
dot_import_whitelist = []
http_status_code_whitelist = ["200", "400", "404", "500"]

huangapple
  • 本文由 发表于 2021年11月3日 00:06:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/69813533.html
匿名

发表评论

匿名网友

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

确定