Golint安裝和使用(Goland)

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校驗規則

  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–
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章