Anonymous struct types are nested three levels deep
What it finds
Spec struct { Limits struct { CPU string } } inside another anonymous struct: types written in place have no name, so they cannot be used in function signatures, their values cannot be built without repeating the whole type, and deep nesting makes the shape hard to read. A named type for the inner structure avoids that.
Reported is an anonymous struct type written inside another anonymous struct type that is itself nested in a struct, that is, the third level of anonymous structs. A single level, common for configuration and test tables, is left alone.
From the rule's source, nested_anonymous_struct.rs.
package p type Config struct { Spec struct { Limits struct {tx0 reports: this anonymous struct is nested inside two others CPU string } Name string }} var table = []struct { name string want struct{ ok bool }}{} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:nested-anonymous-struct" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:nested-anonymous-struct] reason="..."tx0 explain tx0/go:nested-anonymous-struct shows the same in the terminal. Found a false positive? Report it.