aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/sort.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:47:15 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:47:15 +0200
commit89c1fcd8fae93a64d304251a35a65763818aa8b1 (patch)
treec695ff9c729a12eeab63d8a7743a6d789f64de27 /cmd/krino/sort.go
parent97c8164bc81e0a438dab92d7244485005dac4ff2 (diff)
downloadkrino-89c1fcd8fae93a64d304251a35a65763818aa8b1.tar.gz
krino-89c1fcd8fae93a64d304251a35a65763818aa8b1.zip
--json carries exclusions and matching warnings
Diffstat (limited to 'cmd/krino/sort.go')
-rw-r--r--cmd/krino/sort.go16
1 files changed, 15 insertions, 1 deletions
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...)