Golang lint簡易使用方法

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

根據作者的說法:

Golint is a linter for Go source code.Golint differs from gofmt. Gofmt reformats Go source code, whereasgolint prints out style mistakes.Golint differs from govet. Govet is concerned with correctness, whereasgolint is concerned with coding style. Golint is in use at Google, and itseeks to match the accepted style of the open source Go project.

一句話就是Golint用於檢查go代碼中不夠規範的地方。

一、編譯及產生可執行程式

1、下載golang 的 lint,下載地址:https://github.com/golang/lint

2、解壓檔案到$GOPATH/src/github.com/golang/lint

3、到目錄$GOPATH/src/github.com/golang/lint/golint中運行go build ./

4、在目前的目錄有golint的可執行程式

當然,最簡單的方式是:

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

二、執行方式:

golint 檔案名稱或者目錄

檢查結果如下:

import-dot.go:6:8: should not use dot importselse.go:11:9: if block ends with a return statement, so drop this else and outdent its blocksort.go:11:1: exported method T.Len should have comment or be unexportedsort.go:20:1: exported method U.Other should have comment or be unexported

從上面輸出可以看到,golint對go代碼給出的建議。

golint 會檢查的內容:

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







相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.