1 下载Golint及解压
- 下载golang的lint,下载地址github.com/golang/lint
- 解压文件到$GOPATH/src/github.com/goland/lint下面
- 到目录$GOPATH/src/github.com/goland/lint/golint中运行 go build ./
- 在目录中就会生成一个golint的可执行文件
2 GoLand配置Golint
- 打开goland的setting->tool->External Tools 如图
2.点击+符号
| 名称 | 属性 |
|---|---|
| program | 刚刚生成的golint可执行文件 |
| Arguments | $FilePath$ |
| working directory | $ProjectFileDir$ |
3 使用golint
找到一个包或者文件右键
实例:比如方法名首字符大写的话,执行结果如图
4 golint 常见错误
-
don't use ALL_CAPS in Go names; use CamelCase
不能使用下划线命名法,使用驼峰命名法 -
exported function Xxx should have comment or be unexported
外部可见程序结构体、变量、函数都需要注释 -
var statJsonByte should be statJSONByte
var taskId should be taskID
通用名词要求大写
iD/Id -> ID
Http -> HTTP
Json -> JSON
Url -> URL
Ip -> IP
Sql -> SQL -
don't use an underscore in package name
don't use MixedCaps in package name; xxXxx should be xxxxx
包命名统一小写不使用驼峰和下划线 -
comment on exported type Repo should be of the form "Repo ..." (with optional leading article)
注释第一个单词要求是注释程序主体的名称,注释可选不是必须的 -
type name will be used as user.UserModel by other packages, and that stutters; consider calling this Model
外部可见程序实体不建议再加包名前缀 -
if block ends with a return statement, so drop this else and outdent its block
if语句包含return时,后续代码不能包含在else里面 -
should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
errors.New(fmt.Sprintf(…)) 建议写成 fmt.Errorf(…) -
receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"
receiver名称不能为this或self -
error var SampleError should have name of the form ErrSample
错误变量命名需以 Err/err 开头 -
should replace num += 1 with num++
should replace num -= 1 with num--
a+=1应该改成a++,a-=1应该改成a–