A struct tag is malformed or its fields' names conflict
What it finds
Struct tags that reflect.StructTag.Get cannot read, keys that appear twice, json and xml options that do not exist or contain a space, and fields of one struct that claim the same json name, which makes encoding/json ignore all of them.
A tag is read the way reflect reads it: key:"value" pairs separated by spaces, a key being a run of characters other than spaces, quotes, colons and control characters, and a value a quoted Go string. reflect gives up silently at the first pair it cannot read, so every key from there on is lost. An unknown json option is reported only when it is close to a known one, such as omitempy, since other packages add options of their own to json tags; xml tags are read by encoding/xml alone. Fields without a tag, unexported fields and the name - take part in no comparison of names.
From the rule's source, struct_tag.rs.
package p type Config struct { Name string `json:"name,omitempty" yaml:"name"` Unquoted string `json:name`tx0 reports: this struct tag cannot be read: the value of json is not quoted Spaced string `json: "spaced"`tx0 reports: the value of json is not quoted NoColon string `json`tx0 reports: the key json is not followed by : Open string `json:"open`tx0 reports: the value of json is not a valid string Twice string `json:"a" json:"b"`tx0 reports: the key json twice Typo string `json:"typo,omitempy"`tx0 reports: omitempy is not a json option; did you mean omitempty? Space string `json:"space, omitempty"`tx0 reports: the json option omitempty contains a space Spaces string `json:"two words"` XMLSpace string `xml:"x "`tx0 reports: the xml name x starts or ends with a space XMLTypo string `xml:"y,attribute"`tx0 reports: attribute is not an xml option Other string `json:",omitzero,inline,format:RFC3339" xml:"z,attr,omitempty"` Custom string `json:",intern" mapstructure:",squash"` Escaped string "json:\"escaped\"" Empty string `` _ struct{} Inner struct { A string `json:"a"` B string `json:"a"`tx0 reports: the json name a is used by more than one field } First int `json:"id"` Second int `json:"id,omitempty"`tx0 reports: the json name id is used by more than one field hidden int `json:"name"` Skip1 int `json:"-"` Skip2 int `json:"-"` Dash int `json:"-,"` Both, Neither int `json:"both"`tx0 reports: the json name both is used by more than one field Unnamed int `json:",omitempty"`} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:struct-tag" = "off"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:struct-tag] reason="..."tx0 explain tx0/go:struct-tag shows the same in the terminal. Found a false positive? Report it.