~/bend-docscommunity

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).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{"strings", "C008", "correctness"},    Entry{"chars", "C009", "correctness"},    Entry{"foreign", "C010", "correctness"},    Entry{"unused", "U001", "suspicious"},    Entry{"strict", "U002", "suspicious"},    Entry{"eager", "U003", "suspicious"},    Entry{"concat", "U004", "suspicious"},    Entry{"fuel", "U006", "suspicious"},    Entry{"index", "U007", "suspicious"},    Entry{"table", "U008", "suspicious"},    Entry{"hoist", "U009", "suspicious"},    Entry{"ring", "U010", "suspicious"},    Entry{"rewalk", "U011", "suspicious"},    Entry{"unit", "U012", "suspicious"},    Entry{"doc", "S001", "style"},    Entry{"space", "S002", "style"},    Entry{"wrap", "S003", "style"},    Entry{"param", "S004", "style"},    Entry{"noqa", "S005", "style"},    Entry{"coverage", "L001", "laws"},    Entry{"closed", "L002", "laws"},    Entry{"unsafe", "L003", "laws"},    Entry{"trace", "L005", "laws"},    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))