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). 7 import Base 8 import ./lazy/lazy.bend as Lazy 9 10 # one rule: the slug bolt.bend names, its code, its group 11 type Entry is Data: 12 Entry{slug: String, id: String, grp: String} 13 14 # every rule, in group order 15 def table() -> List<&2, Entry>: 16 [ 17 Entry{"hole", "C002", "correctness"}, 18 Entry{"pick", "C003", "correctness"}, 19 Entry{"put", "C004", "correctness"}, 20 Entry{"arms", "C005", "correctness"}, 21 Entry{"escape", "C006", "correctness"}, 22 Entry{"twice", "C007", "correctness"}, 23 Entry{"strings", "C008", "correctness"}, 24 Entry{"chars", "C009", "correctness"}, 25 Entry{"foreign", "C010", "correctness"}, 26 Entry{"unused", "U001", "suspicious"}, 27 Entry{"strict", "U002", "suspicious"}, 28 Entry{"eager", "U003", "suspicious"}, 29 Entry{"concat", "U004", "suspicious"}, 30 Entry{"fuel", "U006", "suspicious"}, 31 Entry{"index", "U007", "suspicious"}, 32 Entry{"table", "U008", "suspicious"}, 33 Entry{"hoist", "U009", "suspicious"}, 34 Entry{"ring", "U010", "suspicious"}, 35 Entry{"rewalk", "U011", "suspicious"}, 36 Entry{"unit", "U012", "suspicious"}, 37 Entry{"doc", "S001", "style"}, 38 Entry{"space", "S002", "style"}, 39 Entry{"wrap", "S003", "style"}, 40 Entry{"param", "S004", "style"}, 41 Entry{"noqa", "S005", "style"}, 42 Entry{"coverage", "L001", "laws"}, 43 Entry{"closed", "L002", "laws"}, 44 Entry{"unsafe", "L003", "laws"}, 45 Entry{"trace", "L005", "laws"}, 46 Entry{"tail", "P001", "pedantic"}] 47 48 # this row is the slug 49 def find.same(+row: Entry, +slug: String) -> Bool: 50 Entry{+s, _id, _grp} = row 51 String.eq(s, slug) 52 53 # the row for a slug 54 def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>: 55 match rows: 56 case Nil{}: 57 None{} 58 case Con{+row, rest}: 59 Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug)) 60 61 # the stable code; the slug itself when it is not a rule 62 def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String: 63 match mm: 64 case None{}: 65 slug 66 case Some{Entry{_s, +id, _grp}}: 67 id 68 69 # the stable code; the slug itself when it is not a rule 70 def code(+slug: String) -> String: 71 code.at(find(table(), slug), slug) 72 73 # the group; empty when the slug is not a rule 74 def group.at(mm: Maybe<&2, Entry>) -> String: 75 match mm: 76 case None{}: 77 "" 78 case Some{Entry{_s, _id, +grp}}: 79 grp 80 81 # the group; empty when the slug is not a rule 82 def group(+slug: String) -> String: 83 group.at(find(table(), slug)) 84 85 # `bolt(group:slug)`; `bolt` when the slug is not a rule 86 def source.at(mm: Maybe<&2, Entry>) -> String: 87 match mm: 88 case None{}: 89 "bolt" 90 case Some{Entry{+s, _id, +grp}}: 91 "bolt(" ++ grp ++ ":" ++ s ++ ")" 92 93 # `bolt(group:slug)`; `bolt` when the slug is not a rule 94 def source(+slug: String) -> String: 95 source.at(find(table(), slug))