smrcptr
v1.4.1
لا تقم بخلط أنواع المتلقي. اختر إما مؤشرات أو أنواع بنية لجميع الطرق المتاحة.
يحتوي GO على قواعد حول كيفية اختيار مستقبلات القيمة أو الأسلوب تلقائيًا ، والتي يمكن أن تؤدي إلى الأخطاء. لذلك ، إنها توصية نمط شائعة 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 اعتبارًا من 2022-11-30 ، لا يكتشف أن مستقبلات طريقة المؤشر والقيمة مختلطة. معظم المحللات ذات الصلة ST1016 يتحقق فقط من اسم مستقبل الطريقة.
$ staticcheck -checks ST1016 ./...
main.go:9:18: methods on the same type should have the same receiver name (seen 1x " v " , 2x " s " ) (ST1016)استخدام جميع التحليلات لا يكتشفها أيضًا.
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 ↩
Google Go Style Guide https://google.github.io/styleguide/go/decisions#receiver-type ↩