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)wiki https://github.com/golang/go/wiki/codereviewcomments#receiver-type ↩
Google Go 스타일 가이드 https://google.github.io/styleguide/go/decisions#receiver-type ↩