src/codes.bend
bolt@1.21.0.0 · 101 lines · 0 definitions
1# src/codes: the stable id of every rule. A bolt.bend still names the slug
2# (`wrap`); a diagnostic shows the code (`S003`) and, in an editor, the
3# source `bolt(group:slug)`. Numbers are assigned once, in the group order
4# of src/README.md: do not renumber a rule, and do not reuse a retired code
5# (L004 was `quantify`, now `closed` itself; C001 was `shadow` and U005 was
6# `nat`, whose failures bend 2.0.25 no longer has; U014 was `argv`, retired
7# before its first release, since every reader already drops the program).
8import Base
9import bolt@1.21.0.0/src/lazy/lazy.bend as Lazy
10
11# one rule: the slug bolt.bend names, its code, its group
12type Entry is Data:
13 Entry{slug: String, id: String, grp: String}
14
15# every rule, in group order
16def table() -> List<&2, Entry>:
17 [
18 Entry{"hole", "C002", "correctness"},
19 Entry{"pick", "C003", "correctness"},
20 Entry{"put", "C004", "correctness"},
21 Entry{"arms", "C005", "correctness"},
22 Entry{"escape", "C006", "correctness"},
23 Entry{"twice", "C007", "correctness"},
24 Entry{"strings", "C008", "correctness"},
25 Entry{"chars", "C009", "correctness"},
26 Entry{"foreign", "C010", "correctness"},
27 Entry{"setting", "C011", "correctness"},
28 Entry{"unused", "U001", "suspicious"},
29 Entry{"strict", "U002", "suspicious"},
30 Entry{"eager", "U003", "suspicious"},
31 Entry{"concat", "U004", "suspicious"},
32 Entry{"fuel", "U006", "suspicious"},
33 Entry{"index", "U007", "suspicious"},
34 Entry{"table", "U008", "suspicious"},
35 Entry{"hoist", "U009", "suspicious"},
36 Entry{"ring", "U010", "suspicious"},
37 Entry{"rewalk", "U011", "suspicious"},
38 Entry{"unit", "U012", "suspicious"},
39 Entry{"scan", "U013", "suspicious"},
40 Entry{"thunk", "U015", "suspicious"},
41 Entry{"fromrev", "U016", "suspicious"},
42 Entry{"doc", "S001", "style"},
43 Entry{"space", "S002", "style"},
44 Entry{"wrap", "S003", "style"},
45 Entry{"param", "S004", "style"},
46 Entry{"noqa", "S005", "style"},
47 Entry{"transcong", "S006", "style"},
48 Entry{"coverage", "L001", "laws"},
49 Entry{"closed", "L002", "laws"},
50 Entry{"unsafe", "L003", "laws"},
51 Entry{"trace", "L005", "laws"},
52 Entry{"tail", "P001", "pedantic"}]
53
54# this row is the slug
55def find.same(+row: Entry, +slug: String) -> Bool:
56 Entry{+s, _id, _grp} = row
57 String.eq(s, slug)
58
59# the row for a slug
60def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
61 match rows:
62 case Nil{}:
63 None{}
64 case Con{+row, rest}:
65 Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
66
67# the stable code; the slug itself when it is not a rule
68def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
69 match mm:
70 case None{}:
71 slug
72 case Some{Entry{_s, +id, _grp}}:
73 id
74
75# the stable code; the slug itself when it is not a rule
76def code(+slug: String) -> String:
77 code.at(find(table(), slug), slug)
78
79# the group; empty when the slug is not a rule
80def group.at(mm: Maybe<&2, Entry>) -> String:
81 match mm:
82 case None{}:
83 ""
84 case Some{Entry{_s, _id, +grp}}:
85 grp
86
87# the group; empty when the slug is not a rule
88def group(+slug: String) -> String:
89 group.at(find(table(), slug))
90
91# `bolt(group:slug)`; `bolt` when the slug is not a rule
92def source.at(mm: Maybe<&2, Entry>) -> String:
93 match mm:
94 case None{}:
95 "bolt"
96 case Some{Entry{+s, _id, +grp}}:
97 "bolt(" ++ grp ++ ":" ++ s ++ ")"
98
99# `bolt(group:slug)`; `bolt` when the slug is not a rule
100def source(+slug: String) -> String:
101 source.at(find(table(), slug))