golint---golang代码质量检测

github: https://github.com/golang/lintjavascript

golint是相似javascript中的jslint的工具,主要功能就是检测代码中不规范的地方。golint用于检测go代码。java

使用

$ go get github.com/golang/lint
$ go install github.com/golang/lint

golint 文件名或者目录
检测对应的代码。git

golint会输出一些代码存在的问题:
好比:github

recorder.go:55:5: exported var RecordBind should have comment or be unexported
recorder.go:158:1: exported function Record_ErrorRecord should have comment or be unexported
recorder.go:173:6: don't use underscores in Go names; type Data_MemStats should be DataMemStats
recorder.go:179:2: struct field FreeRam should be FreeRAM

上面的输出中文件recorder.go,179行,在struct中字段FreeRam应该是 FreeRAM,输出信息很是的详细golang

golint 会检测的方面:工具

  • 变量名规范
  • 变量的声明,像var str string = "test",会有警告,应该var str = "test"
  • 大小写问题,大写导出包的要有注释
  • x += 1 应该 x++

等等
详细能够看官方库示例,https://github.com/golang/lint/tree/master/testdatacode

相关文章
相关标签/搜索