1、安装golint
首先在我们下载的位置,通过右键git bash here 打开git控制台
然后输入命令:git clone https://github.com/golang/lint.git
进行项目克隆
之后通过cd lint/golint
进入安装目录
最后通过go install命令进行安装
安装成功后我们会在C:\Users\admin\go\bin 目录下面看到我们的golint.exe执行程序,这个目录是我们安装go包的目录路径
2、配置golint
1、打开Idea
2、选择项目栏File 下拉选中 Setting,打开设置控制面板
3、 选择External Tools,新添加一个工具配置:
4、选中keymap > External Tools > External Tools > golint进行快捷键配置
3、golint使用
选择我们需要检测的go文件
按住我们之前设置的快捷键,就可以进行检测了,比如说结果如下:
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–