ptrrecv

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 7 Imported by: 0

README

yze-go-ptrrecv

A yze analyzer (category immutability) enforcing the gomatic Go immutability standard: methods use value receivers, never pointer receivers, unless the receiver type transitively contains a field that cannot be copied (a sync primitive, sync/atomic type, bytes.Buffer, or strings.Builder).

Pointer receivers imply mutability — and on exported types that leaks into interface semantics and concurrency expectations. This analyzer flags every pointer-receiver method whose type holds no no-copy field.

The rule is intentionally narrow: only a transitively-uncopyable field justifies a pointer receiver. Mutation and interface-satisfaction are deliberately not carve-outs — that narrowness reflects the gomatic immutability preference. The no-copy walk recurses through nested structs and through array elements (an array stores its elements inline, so a no-copy element makes the array uncopyable), but not through slices, maps, channels, or pointers, which are references that leave the enclosing struct copyable.

  • Rule: yze/ptrrecv
  • No-copy types: 16 baked-in standard-library types, extensible at runtime via the -allow flag (comma-separated fully-qualified pkgpath.Name entries).
  • Binary: cmd/yze-go-ptrrecv runs it standalone (text/-json, and as a go vet -vettool).

Built on the go-yze framework.

Documentation

Overview

Package ptrrecv provides a go/analysis analyzer enforcing the gomatic Go immutability standard: methods use value receivers, never pointer receivers, unless the receiver type transitively contains a field that cannot be copied (a sync primitive, atomic, buffer, or builder).

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = newAnalyzer()

Analyzer reports pointer-receiver methods on types that need no pointer.

View Source
var Registration = goyze.Registration{
	Name:       "ptrrecv",
	Categories: []goyze.Category{"immutability"},
	URL:        "https://docs.gomatic.dev/yze/ptrrecv",
	Analyzer:   Analyzer,
}

Registration declares this analyzer to the yze framework.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
yze-go-ptrrecv command
Command yze-go-ptrrecv runs the ptrrecv analyzer as a standalone go/analysis checker (text, -json, and -fix output, and as a `go vet -vettool`).
Command yze-go-ptrrecv runs the ptrrecv analyzer as a standalone go/analysis checker (text, -json, and -fix output, and as a `go vet -vettool`).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL