Documentation
¶
Overview ¶
Package jsontags checks for incompatible usage of JSON struct tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Analyzer = &analysis.Analyzer{ Name: "jsonvet", Doc: "check for incompatible usages of JSON struct tags", Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, }
var PureIsZeroMethodsInTailscaleModule = map[string]set.Set[string]{ "tailscale.com/net/packet": set.Of( "TailscaleRejectReason", ), "tailscale.com/tailcfg": set.Of( "UserID", "LoginID", "NodeID", "StableNodeID", ), "tailscale.com/tka": set.Of( "AUMHash", ), "tailscale.com/types/geo": set.Of( "Point", ), "tailscale.com/tstime/mono": set.Of( "Time", ), "tailscale.com/types/key": set.Of( "NLPrivate", "NLPublic", "DERPMesh", "MachinePrivate", "MachinePublic", "ControlPrivate", "DiscoPrivate", "DiscoPublic", "DiscoShared", "HardwareAttestationPublic", "ChallengePublic", "NodePrivate", "NodePublic", ), "tailscale.com/types/netlogtype": set.Of( "Connection", "Counts", ), }
PureIsZeroMethodsInTailscaleModule is a list of known IsZero methods in the "tailscale.com" module that are pure.
Functions ¶
func ParseAllowlist ¶
func ParseAllowlist(s string) map[ReportKind]set.Set[string]
ParseAllowlist parses an allowlist of reports to ignore, which is a newline-delimited list of tuples separated by a tab, where each tuple is a ReportKind and a fully-qualified field name.
For example:
OmitEmptyUnsupportedInV1 tailscale.com/path/to/package.StructType.FieldName OmitEmptyUnsupportedInV1 tailscale.com/path/to/package.*.FieldName
The struct type name may be "*" for anonymous struct types such as those declared within a function or as a type literal in a variable.
func RegisterAllowlist ¶
func RegisterAllowlist(allowlist map[ReportKind]set.Set[string])
RegisterAllowlist registers an allowlist of reports to ignore, which is represented by a set of fully-qualified field names for each ReportKind.
For example:
{
"OmitEmptyUnsupportedInV1": set.Of(
"tailscale.com/path/to/package.StructType.FieldName",
"tailscale.com/path/to/package.*.FieldName",
),
}
The struct type name may be "*" for anonymous struct types such as those declared within a function or as a type literal in a variable.
This must be called at init and the input must not be mutated.
func RegisterPureIsZeroMethods ¶
RegisterPureIsZeroMethods specifies a list of pure IsZero methods where it is identical to calling reflect.Value.IsZero on the receiver. This is not strictly necessary, but allows for more accurate detection of improper use of `json` tags.
This must be called at init and the input must not be mutated.
Types ¶
type ReportKind ¶
type ReportKind string
const ( OmitEmptyUnsupportedInV1 ReportKind = "OmitEmptyUnsupportedInV1" OmitEmptyUnsupportedInV2 ReportKind = "OmitEmptyUnsupportedInV2" OmitEmptyShouldBeOmitZero ReportKind = "OmitEmptyShouldBeOmitZero" OmitEmptyShouldBeOmitZeroButHasIsZero ReportKind = "OmitEmptyShouldBeOmitZeroButHasIsZero" StringOnNonNumericKind ReportKind = "StringOnNonNumericKind" FormatMissingOnTimeDuration ReportKind = "FormatMissingOnTimeDuration" )