1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Output shared by the commands that report findings.
//!
//! `check` and `lint-docs` print the same two things in the same way: a
//! finding line, and the "could not be analyzed" block that carries the exit-2
//! contract. They were transcribed copies, so `lint-docs` inherited a fixed
//! bug by luck rather than by construction: the blank line above the failure
//! block is emitted only when a findings block precedes it, because emitting it
//! unconditionally opened every clean-but-unanalyzed run with a stray empty
//! line.
//!
//! What each command still owns is its own format's shape - `check`'s JSON
//! wire types, `lint-docs`' report-only footer - and the one deliberate
//! difference in the finding line, which is passed as an argument rather than
//! copied.
use BTreeMap;
use Write;
use PathBuf;
use Result;
use crateFinding;
use crateFailureReason;
/// The longest finding message a text line carries.
const MESSAGE_MAX: usize = 200;
/// The longest kind a text line carries. Real ones are a rule or category
/// name; the longest are linter rule paths of a few dozen characters.
const KIND_MAX: usize = 80;
/// The longest suggestion a text line carries. Longer than a message because
/// a suggestion is often a short code fragment.
const SUGGESTION_MAX: usize = 400;
/// One line of text output for a finding.
///
/// `source` is the layer that produced it (`"tool"`, `"llm"`), rendered as a
/// prefix inside the brackets. `check` passes one because two layers write into
/// one list and they gate differently; `lint-docs` passes `None`, because it
/// has a single source and a constant tag on every line says nothing.
///
/// The kind and message are excerpted: a tool's diagnostics and a model's
/// answer are text drep did not write, and JSON decodes `\u001b` into a real
/// escape, so a raw print hands the terminal an escape sequence, a newline
/// forges a line of its own, and a multi-kilobyte field hands it a flood. A
/// model's `category` becomes the kind, and the code under review can steer
/// the model. The file name is the repository's, and is printed through
/// [`crate::text::path_label`] for the same reason.
/// The suggestion line that follows a finding, when it has one.
///
/// Excerpted for the same reason as the message in [`finding_line`]: a
/// model's suggestion is its own text, and printed raw an escape sequence in
/// it reaches the terminal and a newline in it prints a forged finding line.
/// Write [`suggestion_line`], when there is one.
///
/// Written immediately after the finding it belongs to. Printing every finding
/// first and every suggestion afterwards detaches them: with two findings, the
/// first suggestion appears below the second finding and reads as if it
/// belonged to it.
/// The "N file(s) could not be analyzed" block.
///
/// `findings_above` decides the separating blank line - see the module doc.
/// Each file is named through [`crate::text::path_label_of`], as in
/// [`finding_line`].