smrcptr
v1.4.1
Jangan mencampur jenis penerima. Pilih jenis pointer atau struct untuk semua metode yang tersedia.
GO memiliki aturan tentang bagaimana secara otomatis memilih nilai atau metode penerima, yang rumit dan dapat menyebabkan bug. Oleh karena itu, ini adalah rekomendasi gaya umum 1 2 .
go install github.com/nikolaydubina/smrcptr@latest type Pancake struct {}
func NewPancake () Pancake { return Pancake {} }
func ( s * Pancake ) Fry () {}
func ( s Pancake ) Bake () {}$ smrcptr ./...
/pancake.go:12:1: Pancake.Fry uses pointer
/pancake.go:10:1: Pancake.NewPancake uses value
/pancake.go:14:1: Pancake.Bake uses value Pada 2022-11-30 , tidak mendeteksi bahwa penerima metode pointer dan nilai dicampur. Paling Analisis Paling Relevan ST1016 Memeriksa Hanya Nama Penerima Metode.
$ staticcheck -checks ST1016 ./...
main.go:9:18: methods on the same type should have the same receiver name (seen 1x " v " , 2x " s " ) (ST1016)Menggunakan semua penganalisa juga tidak mendeteksinya.
staticcheck -checks all ./...
main.go:9:18: methods on the same type should have the same receiver name (seen 1x " v " , 2x " s " ) (ST1016)Go wiki https://github.com/golang/go/wiki/codereviewcomments#receiver-type ↩
Panduan Gaya Google Go https://google.github.io/styleguide/go/decisions#receiver-type ↩