これはGo的にはあまりやらない方がいいと思うやつなんだけど、こういうこともできるよ、という紹介。
type Hoge struct {
Url string
}
みたいに書いてgolintを実行すると "struct field Url should be URL" と怒られる。しかし、golintには -min_confidence という引数を指定できる。デフォルトは0.8なので、試しにこれを1.0に引き上げてみると"struct field Url should be URL"というエラーは出なくなる。https://github.com/golang/lint/blob/master/lint.go のソースを見てみると、いろいろなチェック処理で
f.errorf(vs, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment%s or be unexported", kind, name, block)
のようにf.errorfの第2引数にConfidenceを指定しているので、該当のエラーを消したい場合は -min_confidence でそのチェック処理のConfidenceより大きい物を指定すれば良さそう。
package main
type Session struct {
Url string
}
func (s *Session) Open() bool {
return true
}
func main() {
s := Session{"https://github.com/"}
s.Open()
}
ためしにこんな感じのソースをgolintにかけるとデフォルトでは
$ golint golint.go
golint/golint.go:3:6: exported type Session should have comment or be unexported
golint/golint.go:7:1: exported method Session.Open should have comment or be unexported
golint/golint.go:4:2: struct field Url should be URL
というエラーが出るけど、-min_confidence=1.1にすると全部出なくなる。あんまりやらない方がいいことだとは思うけど、エラー出まくるからという理由でgolintをかけなくなるよりかは -min_confidence を指定してgolintする方がいいのではないかなぁと思った次第です。