golint---golang代碼品質檢測

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

github: https://github.com/golang/lint

golint是類似javascript中的jslint的工具,主要功能就是檢測代碼中不規範的地方。golint用於檢測go代碼。

使用

$ go get github.com/golang/lint$ go install github.com/golang/lint

golint 檔案名稱或者目錄
檢測對應的代碼。

golint會輸出一些代碼存在的問題:
比如:

recorder.go:55:5: exported var RecordBind should have comment or be unexportedrecorder.go:158:1: exported function Record_ErrorRecord should have comment or be unexportedrecorder.go:173:6: don't use underscores in Go names; type Data_MemStats should be DataMemStatsrecorder.go:179:2: struct field FreeRam should be FreeRAM

上面的輸出中檔案recorder.go,179行,在struct中欄位FreeRam應該是 FreeRAM,輸出資訊非常的詳細

golint 會檢測的方面:

  • 變數名規範
  • 變數的聲明,像var str string = "test",會有警告,應該var str = "test"
  • 大小寫問題,大寫匯出包的要有注釋
  • x += 1 應該 x++

等等
詳細可以看官方庫樣本,https://github.com/golang/lint/tree/master/testdata

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.