Golint安装和使用(Goland) - Go语言中文社区

Golint安装和使用(Goland)


1、安装golint

     首先在我们下载的位置,通过右键git bash here 打开git控制台
     然后输入命令:git clone https://github.com/golang/lint.git进行项目克隆
     之后通过cd lint/golint进入安装目录
     最后通过go install命令进行安装
在这里插入图片描述
     安装成功后我们会在C:Usersadmingobin 目录下面看到我们的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校验规则

  1. don’t use ALL_CAPS in Go names; use CamelCase
          不能使用下划线命名法,使用驼峰命名法
  2. exported function Xxx should have comment or be unexported
          外部可见程序结构体、变量、函数都需要注释
  3. var statJsonByte should be statJSONByte
    var taskId should be taskID
         通用名词要求大写
         iD/Id -> ID
         Http -> HTTP
         Json -> JSON
         Url -> URL
         Ip -> IP
         Sql -> SQL
  4. don’t use an underscore in package name
    don’t use MixedCaps in package name; xxXxx should be xxxxx
         包命名统一小写不使用驼峰和下划线
  5. comment on exported type Repo should be of the form “Repo …” (with optional leading article)
         注释第一个单词要求是注释程序主体的名称,注释可选不是必须的
  6. type name will be used as user.UserModel by other packages, and that stutters; consider calling this Model
         外部可见程序实体不建议再加包名前缀
  7. if block ends with a return statement, so drop this else and outdent its block
         if语句包含return时,后续代码不能包含在else里面
  8. should replace errors.New(fmt.Sprintf(…)) with fmt.Errorf(…)
         errors.New(fmt.Sprintf(…)) 建议写成 fmt.Errorf(…)
  9. receiver name should be a reflection of its identity; don’t use generic names such as “this” or “self”
         receiver名称不能为this或self
  10. error var SampleError should have name of the form ErrSample
         错误变量命名需以 Err/err 开头
  11. should replace num += 1 with num++
    should replace num -= 1 with num–
         a+=1应该改成a++,a-=1应该改成a–
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_34326321/article/details/105122219
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢