src/codes.bend source
src/codes.bend on the hub · documented module
# src/codes: the stable id of every rule. A bolt.bend still names the slug# (`wrap`); a diagnostic shows the code (`S003`) and, in an editor, the# source `bolt(group:slug)`. Numbers are assigned once, in the group order# of src/README.md: do not renumber a rule, and do not reuse a retired code# (L004 was `quantify`, now `closed` itself; C001 was `shadow` and U005 was# `nat`, whose failures bend 2.0.25 no longer has; U014 was `argv`, retired# before its first release, since every reader already drops the program;# U008 `table`, U009 `hoist`, U010 `ring`, U012 `unit` and U013 `scan` were# retired for want of real hits, and L003 `unsafe` since bend 2.0.32 reports# an unsafe def a proof reaches itself). A code names the rule, not its# group: a rule that moves keeps its code (`strings` and `chars` are `perf`,# `foreign` and the cost rules `fuel`, `index`, `strict` and `rewalk` are# `pedantic`).## No law can say this, since it is about versions: a released code is never# renumbered or reused, which review of this table keeps.import Baseimport ./lazy/lazy.bend as Lazy# one rule: the slug bolt.bend names, its code, its grouptype Entry is Data: Entry{slug: String, id: String, grp: String}# every rule, in group orderdef table() -> List<&2, Entry>: [ Entry{"hole", "C002", "correctness"}, Entry{"pick", "C003", "correctness"}, Entry{"put", "C004", "correctness"}, Entry{"arms", "C005", "correctness"}, Entry{"escape", "C006", "correctness"}, Entry{"twice", "C007", "correctness"}, Entry{"setting", "C011", "correctness"}, Entry{"unused", "U001", "suspicious"}, Entry{"eager", "U003", "suspicious"}, Entry{"concat", "U004", "suspicious"}, Entry{"thunk", "U015", "suspicious"}, Entry{"fromrev", "U016", "suspicious"}, Entry{"prefix", "U017", "suspicious"}, Entry{"empty", "U018", "suspicious"}, Entry{"strings", "C008", "perf"}, Entry{"chars", "C009", "perf"}, Entry{"doc", "S001", "style"}, Entry{"space", "S002", "style"}, Entry{"wrap", "S003", "style"}, Entry{"param", "S004", "style"}, Entry{"noqa", "S005", "style"}, Entry{"transcong", "S006", "style"}, Entry{"blank", "S007", "style"}, Entry{"coverage", "L001", "laws"}, Entry{"closed", "L002", "laws"}, Entry{"foreign", "C010", "pedantic"}, Entry{"strict", "U002", "pedantic"}, Entry{"fuel", "U006", "pedantic"}, Entry{"index", "U007", "pedantic"}, Entry{"rewalk", "U011", "pedantic"}, Entry{"tail", "P001", "pedantic"}]# this row is the slugdef find.same(+row: Entry, +slug: String) -> Bool: Entry{+s, _id, _grp} = row String.eq(s, slug)# the row for a slugdef find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>: match rows: case Nil{}: None{} case Con{+row, rest}: Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))# the stable code; the slug itself when it is not a ruledef code.at(mm: Maybe<&2, Entry>, +slug: String) -> String: match mm: case None{}: slug case Some{Entry{_s, +id, _grp}}: id# the stable code; the slug itself when it is not a ruledef code(+slug: String) -> String: code.at(find(table(), slug), slug)# the group; empty when the slug is not a ruledef group.at(mm: Maybe<&2, Entry>) -> String: match mm: case None{}: "" case Some{Entry{_s, _id, +grp}}: grp# the group; empty when the slug is not a ruledef group(+slug: String) -> String: group.at(find(table(), slug))# `bolt(group:slug)`; `bolt` when the slug is not a ruledef source.at(mm: Maybe<&2, Entry>) -> String: match mm: case None{}: "bolt" case Some{Entry{+s, _id, +grp}}: "bolt(" ++ grp ++ ":" ++ s ++ ")"# `bolt(group:slug)`; `bolt` when the slug is not a ruledef source(+slug: String) -> String: source.at(find(table(), slug))