Go语言的静态代码分析(线性)工具

Go语言的静态代码分析(线性)工具

问题描述:

Is there a static analysis tool for Go language –like lint, pylint etc? As far as I googled, I haven't found anything related.

I may do this as an undergrad senior project in my department. I must be sure that it is not done before. Any help is appreciated.

是否有用于Go语言的静态分析工具-如 lint code>, pylint code>等? 就我搜索过的东西而言,我还没有发现任何相关的东西。 p>

我可能会在我系的本科生高级项目中做到这一点。 我必须确保之前没有做过。 感谢您的帮助。 p> div>

Golint is newly released this week: https://github.com/golang/lint

Here are three related tools that you might want to look at. You will see how to parse and analyze Go source code.

govet

gofix

gofmt

In the latest version of go (1.3) godoc includes some static analysis features:

http://golang.org/lib/godoc/analysis/help.html

There are a whole bunch of linters with varying types of output. Some include column offsets, some don't include any context, etc.

I've written a tool called gometalinter that installs, runs and normalises the output of all the ones I'm aware of:

  • structcheck (github.com/opennota/check/cmd/structcheck)
  • golint (github.com/golang/lint/golint)
  • gotype (code.google.com/p/go.tools/cmd/gotype)
  • errcheck (github.com/kisielk/errcheck)
  • defercheck (github.com/opennota/check/cmd/defercheck)
  • varcheck (github.com/opennota/check/cmd/varcheck)
  • go vet

If there are any linters missing I'd love to add them.

There's also a SublimeLinter plugin for it.

If you want a quick look at the state of your entire Go project, ie with various static analysis tools:

You can check out:

http://goreportcard.com

(from http://gophergala.com)

It will check for any issue reported by those four tools in your GitHub repo.

Try megacheck.

megacheck runs staticcheck, gosimple and unused at once. Because it is able to reuse work, it will be faster than running each tool separately.

Visual Studio Code with Go plugin has the support of this linting tool. To enable it, please navigate to Visual Studio Settings and set go.lintTool property to megacheck.

{
  "go.lintTool": "megacheck"
}