From 89c1fcd8fae93a64d304251a35a65763818aa8b1 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 23:47:15 +0200 Subject: --json carries exclusions and matching warnings --- cmd/krino/sort.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'cmd/krino/sort.go') diff --git a/cmd/krino/sort.go b/cmd/krino/sort.go index f600475..83ede11 100644 --- a/cmd/krino/sort.go +++ b/cmd/krino/sort.go @@ -183,7 +183,7 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int { // --json is only ever reached with -n (checked above), and // Ruling 7 is explicit that JSON must never be paged, so // this returns before any of the paging/review code below. - jsonDirs = append(jsonDirs, plan.NewJSONDir(d.Name, d.Root, dp.Chains, dp.Result.Warnings)) + jsonDirs = append(jsonDirs, plan.NewJSONDir(d.Name, d.Root, dp.Chains, fileNotes(dp.Result), dp.Result.Warnings)) return false } @@ -427,6 +427,20 @@ type warnLine struct { // the chain-level warnings (e.g. "moved more than once"), keyed by // Chain.File.Rel; every chain's file is necessarily also in r.Matched (only // matched files ever reach plan.Build), so it is visited exactly once here. +// fileNotes is r's per-file findings - the exclude that set a file aside, +// the warnings matching raised - for the JSON plan. +func fileNotes(r *engine.Result) map[string]plan.FileNotes { + notes := map[string]plan.FileNotes{} + for _, fms := range [][]engine.FileMatch{r.Matched, r.Unmatched} { + for _, fm := range fms { + if fm.Excluded != "" || len(fm.Warnings) > 0 { + notes[fm.File.Rel] = plan.FileNotes{File: fm.File, Excluded: fm.Excluded, Warnings: fm.Warnings} + } + } + } + return notes +} + func collectWarnings(r *engine.Result, chains []plan.Chain) []warnLine { files := make([]engine.FileMatch, 0, len(r.Matched)+len(r.Unmatched)) files = append(files, r.Matched...) -- cgit v1.3