@@ -10,36 +10,45 @@ import (
1010// JSONFormatter outputs diagnostics as a JSON array.
1111type JSONFormatter struct {}
1212
13+ // Fields are ordered pointer-containing (string/slice/pointer) first,
14+ // then scalar (int/bool) last, matching internal/lint.Diagnostic's
15+ // layout. Go's GC computes a struct's ptrdata as the offset through
16+ // the last pointer-containing field; one of these is built per
17+ // diagnostic on every `--format json` run. See
18+ // docs/development/high-performance-go.md "Struct layout".
1319type jsonDiagnostic struct {
14- File string `json:"file"`
15- Line int `json:"line"`
16- Column int `json:"column"`
17- Rule string `json:"rule"`
18- Name string `json:"name"`
19- Severity string `json:"severity"`
20- Message string `json:"message"`
21- SourceLines []string `json:"source_lines,omitempty"`
22- SourceStartLine int `json:"source_start_line,omitempty"`
23- Explanation * jsonExplanation `json:"explanation,omitempty"`
24- // Deprecated and ReplacedBy mirror lint.Diagnostic's plan-136
25- // fields so CI scripts can route a deprecation warning without
26- // scanning the message body. Both are omitempty so non-
27- // deprecation diagnostics stay unchanged on the wire.
28- Deprecated bool `json:"deprecated,omitempty"`
20+ File string `json:"file"`
21+ Rule string `json:"rule"`
22+ Name string `json:"name"`
23+ Severity string `json:"severity"`
24+ Message string `json:"message"`
25+ SourceLines []string `json:"source_lines,omitempty"`
26+ Explanation * jsonExplanation `json:"explanation,omitempty"`
27+ // ReplacedBy mirrors lint.Diagnostic's plan-136 field so CI
28+ // scripts can route a deprecation warning without scanning the
29+ // message body. omitempty so non-deprecation diagnostics stay
30+ // unchanged on the wire.
2931 ReplacedBy string `json:"replaced_by,omitempty"`
3032 // RelatedLocations mirrors lint.Diagnostic's plan-230 field so CI
3133 // scripts can read the schema-constraint location without parsing
3234 // the message. omitempty so diagnostics that carry none stay
3335 // unchanged on the wire. The rule-doc URL is not emitted here — it
3436 // is derivable from the `rule` field and is an editor (LSP) concern.
3537 RelatedLocations []jsonRelatedLocation `json:"related_locations,omitempty"`
38+
39+ Line int `json:"line"`
40+ Column int `json:"column"`
41+ SourceStartLine int `json:"source_start_line,omitempty"`
42+ Deprecated bool `json:"deprecated,omitempty"`
3643}
3744
45+ // File and Message (pointer-containing) precede Line and Column
46+ // (scalar) for the same GC-ptrdata reason as jsonDiagnostic above.
3847type jsonRelatedLocation struct {
3948 File string `json:"file,omitempty"`
49+ Message string `json:"message"`
4050 Line int `json:"line,omitempty"`
4151 Column int `json:"column,omitempty"`
42- Message string `json:"message"`
4352}
4453
4554type jsonExplanation struct {
0 commit comments