src/codes.bend
bolt@1.26.0.0 · 104 lines · 10 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import Base
18import bolt@1.26.0.0/src/lazy/lazy.bend as Lazy
19
20
21type Entry is Data:
22 Entry{slug: String, id: String, grp: String}
23
24
25def table() -> List<&2, Entry>:
26 [
27 Entry{"hole", "C002", "correctness"},
28 Entry{"pick", "C003", "correctness"},
29 Entry{"put", "C004", "correctness"},
30 Entry{"arms", "C005", "correctness"},
31 Entry{"escape", "C006", "correctness"},
32 Entry{"twice", "C007", "correctness"},
33 Entry{"setting", "C011", "correctness"},
34 Entry{"unused", "U001", "suspicious"},
35 Entry{"eager", "U003", "suspicious"},
36 Entry{"concat", "U004", "suspicious"},
37 Entry{"thunk", "U015", "suspicious"},
38 Entry{"fromrev", "U016", "suspicious"},
39 Entry{"prefix", "U017", "suspicious"},
40 Entry{"strings", "C008", "perf"},
41 Entry{"chars", "C009", "perf"},
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{"foreign", "C010", "pedantic"},
51 Entry{"strict", "U002", "pedantic"},
52 Entry{"fuel", "U006", "pedantic"},
53 Entry{"index", "U007", "pedantic"},
54 Entry{"rewalk", "U011", "pedantic"},
55 Entry{"tail", "P001", "pedantic"}]
56
57
58def find.same(+row: Entry, +slug: String) -> Bool:
59 Entry{+s, _id, _grp} = row
60 String.eq(s, slug)
61
62
63def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
64 match rows:
65 case Nil{}:
66 None{}
67 case Con{+row, rest}:
68 Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
69
70
71def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
72 match mm:
73 case None{}:
74 slug
75 case Some{Entry{_s, +id, _grp}}:
76 id
77
78
79def code(+slug: String) -> String:
80 code.at(find(table(), slug), slug)
81
82
83def group.at(mm: Maybe<&2, Entry>) -> String:
84 match mm:
85 case None{}:
86 ""
87 case Some{Entry{_s, _id, +grp}}:
88 grp
89
90
91def group(+slug: String) -> String:
92 group.at(find(table(), slug))
93
94
95def source.at(mm: Maybe<&2, Entry>) -> String:
96 match mm:
97 case None{}:
98 "bolt"
99 case Some{Entry{+s, _id, +grp}}:
100 "bolt(" ++ grp ++ ":" ++ s ++ ")"
101
102
103def source(+slug: String) -> String:
104 source.at(find(table(), slug))