Documentation
¶
Overview ¶
Package jsontag provides a go/analysis analyzer that reports struct field json/yaml tag keys that are not snake_case, per the gomatic data-format standard that serialized keys are snake_case. A key must match ^[a-z0-9]+(_[a-z0-9]+)*$ — lowercase ASCII words separated by single underscores. The empty key and the "-" (skip) key are never checked, and tag options after the first comma (",omitempty", ",string") are ignored.
Keys beginning with "@" are sanctioned: they are JSON-LD keywords (@context, @id, @type, @value, @language, @graph, …) mandated by external specifications (W3C Verifiable Credentials and other JSON-LD vocabularies). Like the `$schema` marker below, the "@" prefix itself marks externally specified wire syntax rather than a naming-style choice, and external specs own that namespace entirely — so the remainder of an @-prefixed key is never snake_case-checked.
Two exemptions cover struct types whose keys mirror a document defined by an external producer and so are not the module's to choose:
Schema mirrors: a file declaring a struct field whose json key is `$schema` — JSON Schema's self-description marker — is exempt as a whole; it reproduces an externally defined document (SARIF, a JSON-Schema catalog).
Decode-only mirrors: a struct type is exempt when it is reachable — through pointers, slices, arrays, map values, named types, type aliases, generic instantiations (both the generic declaration and its type arguments), and struct fields — from a decode call target (the second argument of an Unmarshal(data, target), the sole argument of a Decode(target); matched by callee name and arity) and never reachable from an encode argument (Marshal, MarshalIndent, Encode). Such a graph is only ever populated from a foreign producer's document. _test.go files are ignored when computing this exemption: test usage neither grants it (a decode only in a test exempts nothing) nor revokes it (a round-trip test's Marshal does not cancel a production decode-only mirror).
Decode-only mirror detection: struct graphs that only flow into Unmarshal/Decode reproduce an external producer's document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Analyzer = &analysis.Analyzer{
Name: "jsontag",
Doc: "reports struct field json/yaml tag keys that are not snake_case, per the gomatic data-format standard",
Run: run,
}
Analyzer reports struct field json/yaml tag keys that are not snake_case.
var Registration = goyze.Registration{ Name: "jsontag", Categories: []goyze.Category{"data"}, URL: "https://docs.gomatic.dev/yze/jsontag", 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-jsontag
command
Command yze-go-jsontag runs the jsontag analyzer as a standalone go/analysis checker (text and -json output, and usable as a `go vet -vettool`).
|
Command yze-go-jsontag runs the jsontag analyzer as a standalone go/analysis checker (text and -json output, and usable as a `go vet -vettool`). |