src/finding.bend
bolt@1.26.0.0 · 24 lines · 0 definitions
1# src/finding: what a rule reports. Shown as `path:line:col: level: CODE:
2# message` (line and col 1-based, as editors count; CODE is the stable id in
3# src/codes.bend), so a terminal can jump to it; an editor gets it as a
4# diagnostic over `len` characters from the column (0: to the end of the
5# line), with that code and source `bolt(group:slug)`. The level is the
6# project's (bolt.bend), not the rule's: a rule only finds. `rule` on a
7# finding is still the slug.
8import Base
9import bolt@1.26.0.0/src/config.bend as Config
10import bolt@1.26.0.0/src/codes.bend as Codes
11
12# where (and how far), which rule, what
13type Finding is Data:
14 Finding{path: String, line: U32, col: U32, len: U32, rule: String, msg: String}
15
16# a finding at the level the project set for its rule
17type Graded is Data:
18 Graded{level: Config.Level, finding: Finding}
19
20# one line, `path:line:col: level: CODE: message`
21def show_graded(gg: Graded) -> String:
22 Graded{level, Finding{path, line, col, len, rule, msg}} = gg
23 path ++ ":" ++ U32.show((line + 1 : U32)) ++ ":" ++ U32.show((col + 1 : U32)) ++ ": " ++ Config.show(level) ++ ": "
24 ++ Codes.code(rule) ++ ": " ++ msg