Documentation
¶
Overview ¶
The -allow configuration channel: the extra no-copy types a repository declares. A disablement channel that does not check its own input cannot be audited — an entry that matches nothing looks exactly like one that works — so every entry is validated as it is set, and a rejected entry fails the run.
Recognizing the New+Type constructor naming convention. The prefix marks a constructor only at a word boundary, so a name that merely starts with the letters "New" (Newton, News) is one word, not New+Type, and is never judged.
Module ownership: valuector judges only a pointer to a type the analyzed module declares. A foreign type follows its own library's convention.
Package valuector provides a go/analysis analyzer enforcing the gomatic Go immutability standard: an exported constructor (a New* function) returns a value, not a pointer, unless the constructed type cannot be copied — it is itself a no-copy type, it is defined over one, or it transitively contains a no-copy element through a struct or an array (a sync primitive, an atomic, a bytes.Buffer, a strings.Builder, a bufio Reader/Writer/Scanner, a math/rand.Rand, or a type satisfying the vet copylocks locker shape, the noCopy marker idiom).
A type whose values are HELD BY REFERENCE is exempt too, signalled by a method taking a pointer receiver: returning it by value hands every caller an independent copy, and mutations through one stop being visible through another. See [heldByReference].
A result is a pointer whatever spelling declares it: *T, an alias to *T, and a defined pointer type (type handle *T) are the same result, so naming the pointer does not put a constructor out of scope.
One diagnostic is reported per offending RESULT, at that result's own position, so a constructor declaring two pointer results produces two findings an author can tell apart and answer one at a time.
Scope ¶
valuector judges only a pointer to a named type the analyzed MODULE declares. A foreign pointee is exempt: math/rand.Rand carries no sync field yet advances its state through the pointer, so a library's own convention decides its copy semantics, not this module's design. Module ownership is a path SEGMENT boundary, so example.com/modx is foreign to module example.com/mod.
The locker-shape escape is forgeable, and that is deliberate ¶
A type whose POINTER method set has nullary Lock and Unlock, while its value method set does not, is exempt — and two empty methods acquire that shape. The escape is sanctioned rather than closed, because forging the marker acquires the very property the exemption exists for: go vet's copylocks then reports every copy of such a type, and of every struct holding one, so an author who writes the marker to silence this rule has bound the whole program to it. The cost of the escape is exactly the constraint it claims.
Configuration ¶
The -allow flag (analyzer setting "allow") takes a comma-separated list of extra fully-qualified no-copy type names — pkgpath.Name, e.g. example.com/mod/pkg.Handle — merged with the built-in list, never replacing it. An allow-listed type is no-copy both as a FIELD of the constructed type and as the constructed type itself, and so is any type defined over it. Every entry is validated as it is set: an entry that is not a qualified type name is ErrAllowEntry, so a misspelt exemption fails the run instead of silently exempting nothing.
Index ¶
Constants ¶
const ErrAllowEntry errs.Const = "allow entry is not a fully-qualified type name (want pkgpath.Name)"
ErrAllowEntry rejects an -allow entry that is not a fully-qualified type name, so a misspelt exemption is an error at configuration time rather than an exemption that silently matches nothing.
Variables ¶
var Analyzer = newAnalyzer()
Analyzer reports New* constructors that return a pointer to a copyable type.
var Registration = goyze.Registration{ Precision: goyze.PrecisionJudgment, Name: "valuector", Categories: []goyze.Category{"immutability"}, URL: "https://docs.gomatic.dev/yze/valuector", Analyzer: Analyzer, }
Registration declares this analyzer to the yze framework.
Functions ¶
This section is empty.
Types ¶
This section is empty.