Golang lint简易使用方法
发布时间:2020-12-16 18:55:49 所属栏目:大数据 来源:网络整理
导读:根据作者的说法: GolintisalinterforGosourcecode.Golintdiffersfromgofmt.GofmtreformatsGosourcecode,whereasgolintprintsoutstylemistakes.Golintdiffersfromgovet.Govetisconcernedwithcorrectness,whereasgolintisconcernedwithcodingstyle.Golintisin
根据作者的说法: GolintisalinterforGosourcecode. Golintdiffersfromgofmt.GofmtreformatsGosourcecode,whereas golintprintsoutstylemistakes. Golintdiffersfromgovet.Govetisconcernedwithcorrectness,whereas golintisconcernedwithcodingstyle.GolintisinuseatGoogle,andit seekstomatchtheacceptedstyleoftheopensourceGoproject. 一句话就是Golint用于检查go代码中不够规范的地方。 一、编译及生成可执行程序 1、下载golang 的 lint,下载地址:https://github.com/golang/lint 2、解压文件到$GOPATH/src/github.com/golang/lint 3、到目录$GOPATH/src/github.com/golang/lint/golint中运行go build ./ 4、在当前目录有golint的可执行程序 当然,最简单的方式是: gogetgithub.com/golang/lint goinstallgithub.com/golang/lint 二、执行方式: golint文件名或者目录 检查结果如下: import-dot.go:6:8:shouldnotusedotimports else.go:11:9:ifblockendswithareturnstatement,sodropthiselseandoutdentitsblock sort.go:11:1:exportedmethodT.Lenshouldhavecommentorbeunexported sort.go:20:1:exportedmethodU.Othershouldhavecommentorbeunexported 从上面输出可以看到,golint对go代码给出的建议。 golint 会检查的内容: 变量名规范 变量的声明,像varstrstring="test",会有警告,应该varstr="test" 大小写问题,大写导出包的要有注释 x+=1应该x++ 等等…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |