~/bend-docscommunity

src/lint/plan.bend source

src/lint/plan.bend on the hub · documented module

# src/lint/plan: `bolt` (the lint) as a pure planner. It reads a World# (src/lint/world.bend) and returns either the questions it still needs# answered (`wants`) or the Plan: the lines to print and the exit status# (`plan`). The interpreter (src/lint.bend) loops on `wants`, answering each# question by IO, until nothing is wanted, then prints `plan`'s lines and# exits with its status. The design is docs/rfc/bolt-lint-planner.md.## With no files named, the planner walks the tree under `.` as a fold over the# World's listings: a directory not listed yet reads as empty and is asked# for, so each round of the loop lists one more level of the tree. Once every# directory the walk reads is listed, it asks for the text of each source and# of every bolt.bend candidate of their directories, each once.# A directory's candidates are taken once it is resolved against the World's# working directory (Config.home), so a relative path is graded by the same# bolt.bend wherever bolt runs from.# `wants` never parses a file; `plan` parses and lints once, and reads the# settings of each bolt.bend that grades a directory for `setting` (C011). Once every rule# has run and each finding is graded, the noqa comments (src/noqa.bend)# silence what they name, and then the `noqa` rule reports the comments that# silenced nothing.import Baseimport ../lazy/lazy.bend as Lazyimport ./world.bend as Wimport ../finding.bend as Fimport ../src.bend as Srcimport ../role.bend as Roleimport ../rules.bend as Rulesimport ../rules/imports.bend as Importsimport ../config.bend as Configimport ../noqa.bend as Noqaimport ../rules/style/noqa.bend as NoqaRuleimport ../rules/correctness/setting.bend as Settingimport ../syntax/bind.bend as Bind# what `bolt` prints, in order, and the status it exits withtype Plan is Data:  Plan{lines: List<&2, String>, exit: U32}# the lines a plan printsdef lines.of(pl: Plan) -> List<&2, String>:  Plan{lines, _exit} = pl  lines# the status a plan exits withdef exit.of(pl: Plan) -> U32:  Plan{_lines, exit} = pl  exit# ---------------------------------------------------------------------------# the walk: every `.bend` file under `.`, sorted. A hidden name (`.git`,# `.gate`, `.claude`) and `node_modules` are not descended into. The walk keeps# a queue of directories rather than nesting, as Bend has no mutual recursion:# one def shrinks one argument, the fuel, which bounds how many directories are# read.# a directory the walk never descends intodef walk.skipped(+name: String) -> Bool:  Bool.or(String.starts_with(name, "."), String.eq(name, "node_modules"))# an entry's name without the "/" that marks it a directorydef walk.bare(+name: String) -> String:  String.take(name, Nat.sub(String.length(name), 1n))# a name directly under a directory, as a pathdef walk.under(+dir: String, +name: String) -> String:  dir ++ "/" ++ name# the sub-directories of a listing worth descending into, as pathsdef walk.dirs(es: List<&2, String>, +dir: String) -> List<&2, String>:  match es:    case Nil{}:      Nil{}    case Con{+e, rest}:      +more = walk.dirs(rest, dir)      +keep = Bool.and(String.ends_with(e, "/"), Bool.not(walk.skipped(walk.bare(e))))      Bool.pick(List<&2, String>, keep, walk.under(dir, walk.bare(e)) <> more, more)# the `.bend` files of a listing, as paths (a directory's name ends in "/")def walk.bends(es: List<&2, String>, +dir: String) -> List<&2, String>:  match es:    case Nil{}:      Nil{}    case Con{+e, rest}:      +more = walk.bends(rest, dir)      Bool.pick(List<&2, String>, String.ends_with(e, ".bend"), walk.under(dir, e) <> more, more)# a walk once it stops: the `.bend` files it found, and every directory it# read, the last one read firsttype Walk is Data:  Walk{found: List<&2, String>, read: List<&2, String>}# the files a walk founddef walk.found(wk: Walk) -> List<&2, String>:  Walk{found, _read} = wk  found# the directories a walk read, in the order it read themdef walk.read(wk: Walk) -> List<&2, String>:  Walk{_found, read} = wk  List.reverse(&2, String, read)# every `.bend` file under the directories still queued, the fuel bounding how# many directories are read, each read through the World's listing. What is# found is put in front of what came before, not after it, so the walk stays# linear; `files` sorts at the end regardless.def walk(  fuel: Nat,  +world: W.World,  queue: List<&2, String>,  acc: List<&2, String>,  seen: List<&2, String>) -> Walk:  match fuel:    case 0n:      Walk{acc, seen}    case 1n+f:      match queue:        case Nil{}:          Walk{acc, seen}        case Con{+dir, rest}:          +es = W.listing(world, dir)          walk(f, world, List.append(&2, String, rest, walk.dirs(es, dir)),            List.append(&2, String, walk.bends(es, dir), acc), dir <> seen)# how many directories the walk reads at most; past it the walk stops,# silently. A literal, not `U32.to_nat(100000)`: the checker keeps a literal# whole and steps it one at a time, so laws/ScopeWalksWholeTree.bend's law can name the bound,# where it would expand the call in unary and overflow. The compiler emits# the same `U32.to_nat` for either.def limit() -> Nat:  100000n# the walk of the tree under `.`, reading at most `limit()` directoriesdef tree(+world: W.World) -> Walk:  walk(limit(), world, ["."], [], [])# ---------------------------------------------------------------------------# the files of the run# the files named, or every `.bend` file the walk finds when none weredef files.named(paths: List<&2, String>, +world: W.World) -> List<&2, String>:  match paths:    case Nil{}:      +found = walk.found(tree(world))      List.sort(~String, ~String.is_le, found)    case Con{p, rest}:      p <> rest# the files the lint runs overdef files(+world: W.World) -> List<&2, String>:  files.named(W.paths.of(world), world)# a bolt.bend is configuration, not sourcedef is_config(+p: String) -> Bool:  Bool.or(String.eq(p, "bolt.bend"), String.ends_with(p, "/bolt.bend"))# the paths that are sourcedef sources(ps: List<&2, String>) -> List<&2, String>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      +more = sources(rest)      Bool.pick(List<&2, String>, is_config(p), more, p <> more)# the source files of the run, in file-list orderdef inputs(+world: W.World) -> List<&2, String>:  sources(files(world))# a path as the one file it names wherever it is spelled from: resolved# against the working directory when relative, then normalized# (src/rules/imports.bend), so `a.bend`, `./a.bend` and `/w/a.bend` run# from `/w` are onedef abs(+cwd: String, +path: String) -> String:  Imports.norm(Bool.pick(String, String.starts_with(path, "/"), path, cwd ++ "/" ++ path))# each path resolved (abs)def norms(ps: List<&2, String>, +cwd: String) -> List<&2, String>:  match ps:    case Nil{}:      Nil{}    case Con{p, rest}:      abs(cwd, p) <> norms(rest, cwd)# the paths that resolve to none of the paths seendef unseen(ps: List<&2, String>, +cwd: String, +seen: List<&2, String>) -> List<&2, String>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      +more = unseen(rest, cwd, seen)      Bool.pick(List<&2, String>, Imports.has(seen, abs(cwd, p)), more, p <> more)# the files a run reads its roles from: every source the walk of the tree# finds, then each source of the run the walk does not find (one named# outside the working directory), so each file is read once. A file's role# follows the imports, and the file that makes a named file code, a# package's main.bend that imports it, may be named or notdef graph(+world: W.World) -> List<&2, String>:  +found = sources(walk.found(tree(world)))  +cwd = W.cwd.of(world)  List.append(&2, String, found, unseen(inputs(world), cwd, norms(found, cwd)))# ---------------------------------------------------------------------------# what the plan reads# whether a path is among the pathsdef seen.has(ps: List<&2, String>, +pp: String) -> Bool:  match ps:    case Nil{}:      False{}    case Con{p, rest}:      Lazy.or_else(String.eq(p, pp), _u => seen.has(rest, pp))def uniq.fast(ps: List<&2, String>, +ix: Bind.Index) -> List<&2, String>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      +dup = Bind.indexed(ix, p)      +more = uniq.fast(rest, Bind.index.put(Bind.index.depth(), Bind.key(p), ix, p))      Bool.pick(List<&2, String>, dup, more, p <> more)# each path once, where it first appears: a path is kept when it is none of# those seen and none before it (laws/UniqKeepsFirstOccurrences.bend). The# paths met so far are held in the binder's index (src/syntax/bind.bend), each# put in as it is met: a scan of them for every path is the paths squared,# 3 s a round of `wants` on a project of 4,062 filesdef uniq(ps: List<&2, String>, +seen: List<&2, String>) -> List<&2, String>:  uniq.fast(ps, Bind.index(seen))# ---------------------------------------------------------------------------# the packages (laws/ScopePackageRootsFound.bend): every directory the walk reads but `.` whose# listing names a main.bend, in the order the walk reads them; none when files# were named# the directories the walk read that hold a main.bend, `.` left outdef roots.of(ds: List<&2, String>, +world: W.World) -> List<&2, String>:  match ds:    case Nil{}:      Nil{}    case Con{+d, rest}:      +more = roots.of(rest, world)      +root = Bool.and(Bool.not(String.eq(d, ".")), seen.has(W.listing(world, d), "main.bend"))      Bool.pick(List<&2, String>, root, d <> more, more)# the package roots but `.`, as the walk names them (`./w3c`)def roots.named(paths: List<&2, String>, +world: W.World) -> List<&2, String>:  match paths:    case Nil{}:      roots.of(walk.read(tree(world)), world)    case Con{_p, _rest}:      Nil{}# the package roots but `.`def roots(+world: W.World) -> List<&2, String>:  roots.named(W.paths.of(world), world)# each package root as the project rules take it: its directory as a digest# names one (`w3c/`)def packages(rs: List<&2, String>) -> List<&2, String>:  match rs:    case Nil{}:      Nil{}    case Con{r, rest}:      Imports.dir_of(r ++ "/main.bend") <> packages(rest)# the directory of each pathdef dirs.of(ps: List<&2, String>) -> List<&2, String>:  match ps:    case Nil{}:      Nil{}    case Con{p, rest}:      Config.dir_of(p) <> dirs.of(rest)# the directory of every source, each once: every finding's path is a# source's, so these are the directories grading needsdef conf.dirs(+ps: List<&2, String>) -> List<&2, String>:  uniq(dirs.of(ps), [])# the bolt.bend candidates of a directory as a path names it, nearest first:# the directory resolved against the working directory, then each parent up to# the rootdef conf.chain(+world: W.World, dir: String) -> List<&2, String>:  Config.chain(Config.home(W.cwd.of(world), dir))# the bolt.bend candidates of each directory, nearest firstdef conf.cands(ds: List<&2, String>, +world: W.World) -> List<&2, String>:  match ds:    case Nil{}:      Nil{}    case Con{d, rest}:      List.append(&2, String, conf.chain(world, d), conf.cands(rest, world))# the listing of each directory, as a questiondef asks.entries(ds: List<&2, String>) -> List<&2, W.Ask>:  match ds:    case Nil{}:      Nil{}    case Con{d, rest}:      W.Entries{d} <> asks.entries(rest)# the text of each path, as a questiondef asks.texts(ps: List<&2, String>) -> List<&2, W.Ask>:  match ps:    case Nil{}:      Nil{}    case Con{p, rest}:      W.Contents{p} <> asks.texts(rest)# the listings the plan reads: every directory the walk of the tree reads,# whether files were named or not, since a named file's role is read from the# imports of the whole tree (graph)def lists(+world: W.World) -> List<&2, W.Ask>:  asks.entries(walk.read(tree(world)))# the texts the plan reads: each source, every file of the graph, and every# bolt.bend candidate of the sources' directories, each oncedef texts(+world: W.World) -> List<&2, W.Ask>:  +ps = inputs(world)  asks.texts(uniq(List.concat(&2, String, [ps, graph(world), conf.cands(conf.dirs(ps), world)]),    []))# every question the plan reads the World through: the listings, then the# textsdef looks(+world: W.World) -> List<&2, W.Ask>:  List.append(&2, W.Ask, lists(world), texts(world))def unanswered.dirs(rs: List<&2, W.Reply>) -> List<&2, String>:  match rs:    case Nil{}:      Nil{}    case Con{W.Reply{W.Entries{d}, _a}, rest}:      d <> unanswered.dirs(rest)    case Con{W.Reply{W.Contents{_p}, _a}, rest}:      unanswered.dirs(rest)def unanswered.paths(rs: List<&2, W.Reply>) -> List<&2, String>:  match rs:    case Nil{}:      Nil{}    case Con{W.Reply{W.Entries{_d}, _a}, rest}:      unanswered.paths(rest)    case Con{W.Reply{W.Contents{p}, _a}, rest}:      p <> unanswered.paths(rest)def unanswered.hit(a: W.Ask, +dx: Bind.Index, +px: Bind.Index) -> Bool:  match a:    case W.Entries{+d}:      Bind.indexed(dx, d)    case W.Contents{+p}:      Bind.indexed(px, p)def unanswered.fast(asks: List<&2, W.Ask>, +dx: Bind.Index, +px: Bind.Index) -> List<&2, W.Ask>:  match asks:    case Nil{}:      Nil{}    case Con{+a, rest}:      +more = unanswered.fast(rest, dx, px)      Bool.pick(List<&2, W.Ask>, unanswered.hit(a, dx, px), more, a <> more)def unanswered.of(asks: List<&2, W.Ask>, +rs: List<&2, W.Reply>) -> List<&2, W.Ask>:  unanswered.fast(asks, Bind.index(unanswered.dirs(rs)), Bind.index(unanswered.paths(rs)))# the questions a World does not answer yet, in order# (laws/UnansweredAreOpenQuestions.bend). The World answers a question when# some reply holds it, and a scan of the replies for every question is the# questions times the replies (1.8 s a round of `wants` on a project of 4,062# files). So the directories listed and the paths read are each put in the# binder's index (src/syntax/bind.bend) once, and each question asks its owndef unanswered(asks: List<&2, W.Ask>, world: W.World) -> List<&2, W.Ask>:  W.World{_paths, _cwd, rs} = world  unanswered.of(asks, rs)# the listings still open, or, once there are none, the texts still opendef wants.pick(ls: List<&2, W.Ask>, +world: W.World) -> List<&2, W.Ask>:  match ls:    case Nil{}:      unanswered(texts(world), world)    case Con{a, rest}:      a <> rest# the questions a World still leaves open. The file list is known only once# every directory the walk reads is listed, so the texts wait for the walk.def wants(+world: W.World) -> List<&2, W.Ask>:  wants.pick(unanswered(lists(world), world), world)# ---------------------------------------------------------------------------# the findings# a source path and the text the World holds for ittype Got is Data:  Got{path: String, text: Maybe<&2, String>}# each source with what the World answers for itdef gots(ps: List<&2, String>, +world: W.World) -> List<&2, Got>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      Got{p, W.text(world, p)} <> gots(rest, world)# gots, each text read off the World's indexdef gots.ix(ps: List<&2, String>, +ix: W.Ix) -> List<&2, Got>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      Got{p, W.text.ix(ix, p)} <> gots.ix(rest, ix)# one finding for each source that could not be readdef unread(gs: List<&2, Got>) -> List<&2, F.Finding>:  match gs:    case Nil{}:      Nil{}    case Con{Got{+path, None{}}, rest}:      F.Finding{path, 0, 0, 0, "read", "Cannot read this file."} <> unread(rest)    case Con{Got{_path, Some{_text}}, rest}:      unread(rest)# every source that was read, parsed once for every ruledef srcs_of(gs: List<&2, Got>) -> List<&2, Src.Src>:  match gs:    case Nil{}:      Nil{}    case Con{Got{_path, None{}}, rest}:      srcs_of(rest)    case Con{Got{path, Some{text}}, rest}:      Src.of(path, text) <> srcs_of(rest)# a directory and the config its findings are graded bytype Conf is Data:  Conf{dir: String, config: Config.Config}# what the World holds at each pathdef texts.at(ps: List<&2, String>, +world: W.World) -> List<&2, Maybe<&2, String>>:  match ps:    case Nil{}:      Nil{}    case Con{p, rest}:      W.text(world, p) <> texts.at(rest, world)# texts.at, each read off the World's indexdef texts.ix(ps: List<&2, String>, +ix: W.Ix) -> List<&2, Maybe<&2, String>>:  match ps:    case Nil{}:      Nil{}    case Con{p, rest}:      W.text.ix(ix, p) <> texts.ix(rest, ix)# a directory's config: the nearest bolt.bend the World could read among its# candidates, or the defaultsdef conf.near(+world: W.World, dir: String) -> Config.Config:  Config.nearest(texts.at(conf.chain(world, dir), world))# conf.near, its candidates read off the World's indexdef conf.near.ix(+world: W.World, +ix: W.Ix, dir: String) -> Config.Config:  Config.nearest(texts.ix(conf.chain(world, dir), ix))# each directory's configdef confs.at(ds: List<&2, String>, +world: W.World) -> List<&2, Conf>:  match ds:    case Nil{}:      Nil{}    case Con{+d, rest}:      Conf{d, conf.near(world, d)} <> confs.at(rest, world)# confs.at, each directory's candidates read off the World's indexdef confs.at.ix(ds: List<&2, String>, +world: W.World, +ix: W.Ix) -> List<&2, Conf>:  match ds:    case Nil{}:      Nil{}    case Con{+d, rest}:      Conf{d, conf.near.ix(world, ix, d)} <> confs.at.ix(rest, world, ix)# the config of every directory grading needsdef confs(+world: W.World) -> List<&2, Conf>:  confs.at.ix(conf.dirs(inputs(world)), world, W.ix.world(world))# the config of a directory, from the table; one the table does not hold is# worked out the same way (every finding's directory is in the table, so this# never happens in a run)def conf.find(cs: List<&2, Conf>, +world: W.World, +dir: String) -> Config.Config:  match cs:    case Nil{}:      conf.near(world, dir)    case Con{Conf{d, cfg}, rest}:      Lazy.stop(Config.Config, String.eq(d, dir), cfg, _u => conf.find(rest, world, dir))# the config a finding at a path is graded by: its directory'sdef config.at(+cs: List<&2, Conf>, +world: W.World, path: String) -> Config.Config:  conf.find(cs, world, Config.dir_of(path))# every source's findings from the per-file rules, each told its role among# the marks (src/role.bend) and run at the limits its directory's config# setsdef per_file.role(  +cs: List<&2, Conf>,  +world: W.World,  +ms: List<&2, Role.Mark>,  ss: List<&2, Src.Src>) -> List<&2, F.Finding>:  match ss:    case Nil{}:      Nil{}    case Con{s, rest}:      Src.Src{+path, text, toks, tree, bound, items} = s      List.concat(&2, F.Finding, [Rules.on.role(config.at(cs, world, path), Role.of(ms, path),        Src.Src{path, text, toks, tree, bound, items}), per_file.role(cs, world, ms, rest)])# the facts (src/role.bend) of each file the World read, from its text, each# at its path resolved against the working directory (abs)def facts.of(gs: List<&2, Got>, +cwd: String) -> List<&2, Role.Fact>:  match gs:    case Nil{}:      Nil{}    case Con{Got{_path, None{}}, rest}:      facts.of(rest, cwd)    case Con{Got{path, Some{text}}, rest}:      Role.fact.text(abs(cwd, path), text) <> facts.of(rest, cwd)# each path's mark as the path is spelled: its role among marks taken over# resolved paths (abs), neither when it has none theredef marks.key(ps: List<&2, String>, +cwd: String, +ms: List<&2, Role.Mark>) -> List<&2, Role.Mark>:  match ps:    case Nil{}:      Nil{}    case Con{+p, rest}:      Role.Mark{Imports.norm(p), Role.of.norm(ms, abs(cwd, p))} <> marks.key(rest, cwd, ms)# the marks of a run over files named on the line: every file of the graph# read for its imports, the walk taken over their resolved paths, and each# named file's role looked up there as it is nameddef marks.named(+world: W.World) -> List<&2, Role.Mark>:  +cwd = W.cwd.of(world)  marks.key(inputs(world), cwd, Role.marks.facts(facts.of(gots(graph(world), world), cwd)))# the marks a run's roles are read from: over the whole tree, the sources'# own; over files named on the line, the graph's, every file of the tree# read for its imports, so the main.bend that imports a named file makes it# code even when it is not nameddef marks.run(paths: List<&2, String>, +world: W.World, +s: List<&2, Src.Src>) -> List<&2, Role.Mark>:  match paths:    case Nil{}:      Role.marks(s)    case Con{_p, _rest}:      marks.named(world)# the path of the first candidate the World holds a text for, as a list of# one; none when it holds nonedef conf.first(gs: List<&2, Got>) -> List<&2, String>:  match gs:    case Nil{}:      Nil{}    case Con{Got{path, Some{_text}}, _rest}:      [path]    case Con{Got{_path, None{}}, rest}:      conf.first(rest)# the bolt.bend that grades each directory, in directory order: the first of# its candidates the World read, as conf.near reads it; none for a directory# graded by the defaultsdef conf.used(ds: List<&2, String>, +world: W.World) -> List<&2, String>:  match ds:    case Nil{}:      Nil{}    case Con{d, rest}:      List.append(&2, String, conf.first(gots(conf.chain(world, d), world)), conf.used(rest, world))# conf.used, each candidate read off the World's indexdef conf.used.ix(ds: List<&2, String>, +world: W.World, +ix: W.Ix) -> List<&2, String>:  match ds:    case Nil{}:      Nil{}    case Con{d, rest}:      List.append(&2, String, conf.first(gots.ix(conf.chain(world, d), ix)), conf.used.ix(rest, world, ix))# every bolt.bend grading reads, each once, in the order its directories comedef graders(+world: W.World) -> List<&2, String>:  uniq(conf.used.ix(conf.dirs(inputs(world)), world, W.ix.world(world)), [])# the `setting` rule's findings on each bolt.bend the World read, in orderdef settings.at(gs: List<&2, Got>) -> List<&2, F.Finding>:  match gs:    case Nil{}:      Nil{}    case Con{Got{+path, Some{text}}, rest}:      List.append(&2, F.Finding, Setting.check(path, text), settings.at(rest))    case Con{Got{_path, None{}}, rest}:      settings.at(rest)# the `setting` rule's findings: each unknown setting of every bolt.bend# grading reads (src/rules/correctness/setting.bend)def settings(+world: W.World) -> List<&2, F.Finding>:  settings.at(gots(graders(world), world))# every finding of every rule, ungraded, from the sources and what the World# answers for them: the read failures, the per-file findings of each source,# then `setting`'s over each bolt.bend grading reads, then the project rules'# over every source and the other packagesdef found.at(  +cs: List<&2, Conf>,  +world: W.World,  +gs: List<&2, Got>,  +s: List<&2, Src.Src>) -> List<&2, F.Finding>:  List.concat(&2, F.Finding, [unread(gs), per_file.role(cs, world, marks.run(W.paths.of(world), world, s), s),    settings(world), Rules.project(s, packages(roots(world)))])# every finding of every rule, ungradeddef found(+world: W.World) -> List<&2, F.Finding>:  +gs = gots(inputs(world), world)  found.at(confs(world), world, gs, srcs_of(gs))# ---------------------------------------------------------------------------# grading# every finding graded by the config of its directory, in order, the ones at# off droppeddef grade(+cs: List<&2, Conf>, +world: W.World, fs: List<&2, F.Finding>) -> List<&2, F.Graded>:  match fs:    case Nil{}:      Nil{}    case Con{F.Finding{+path, line, col, len, rule, msg}, rest}:      cfg = config.at(cs, world, path)      List.append(&2, F.Graded, Rules.graded(cfg, [F.Finding{path, line, col, len, rule, msg}]), grade(cs, world, rest))# every source's findings from the per-file rules its directory's config# does not set off, each told its role among the marksdef per_file.live(  +cs: List<&2, Conf>,  +world: W.World,  +ms: List<&2, Role.Mark>,  ss: List<&2, Src.Src>) -> List<&2, F.Finding>:  match ss:    case Nil{}:      Nil{}    case Con{s, rest}:      Src.Src{+path, text, toks, tree, bound, items} = s      List.concat(&2, F.Finding, [Rules.on.role.live(config.at(cs, world, path), Role.of(ms, path),        Src.Src{path, text, toks, tree, bound, items}), per_file.live(cs, world, ms, rest)])# every finding of every rule that can be graded on, ungraded: found.at, a# per-file rule its file's config sets off not rundef found.live(  +cs: List<&2, Conf>,  +world: W.World,  +gs: List<&2, Got>,  +s: List<&2, Src.Src>) -> List<&2, F.Finding>:  List.concat(&2, F.Finding, [unread(gs), per_file.live(cs, world, marks.run(W.paths.of(world), world, s), s),    settings(world), Rules.project(s, packages(roots(world)))])# ---------------------------------------------------------------------------# silencing, then the `noqa` rule# the `noqa` rule's findings on each file's marks, against the graded# findings, each put at its file as a per-file rule's aredef noqa(ms: List<&2, Noqa.Marks>, +whole: Bool, +gs: List<&2, F.Graded>) -> List<&2, F.Finding>:  match ms:    case Nil{}:      Nil{}    case Con{Noqa.Marks{+path, mks}, rest}:      List.append(&2, F.Finding, Rules.on.at(path, NoqaRule.check(mks, whole, path, gs)), noqa(rest, whole, gs))# the graded findings no mark silences, in order, then the `noqa` rule's,# graded by the grader given: nothing silences what `noqa` reportsdef after(  +ms: List<&2, Noqa.Marks>,  +whole: Bool,  +gs: List<&2, F.Graded>,  grader: List<&2, F.Finding> -> List<&2, F.Graded>) -> List<&2, F.Graded>:  List.append(&2, F.Graded, Noqa.keep(ms, gs), grader(noqa(ms, whole, gs)))# every finding of the run, graded, then silenced by the marks of the# sources, then `noqa`'s own, which judges a project rule's code only when# the run is the whole tree. The sources are parsed once for both.def final(+world: W.World) -> List<&2, F.Graded>:  +gs = gots(inputs(world), world)  +s = srcs_of(gs)  +cs = confs(world)  after(Noqa.of_srcs(s), List.is_empty(&2, String, W.paths.of(world)), grade(cs, world, found.at(cs, world, gs, s)),    fs => grade(cs, world, fs))# final, a per-file rule its file's config sets off not run: the same graded# findings (laws/OffRulesAreNotRun.bend)def final.live(+world: W.World) -> List<&2, F.Graded>:  +gs = gots(inputs(world), world)  +s = srcs_of(gs)  +cs = confs(world)  after(Noqa.of_srcs(s), List.is_empty(&2, String, W.paths.of(world)),    grade(cs, world, found.live(cs, world, gs, s)), fs => grade(cs, world, fs))# ---------------------------------------------------------------------------# the plan# one more at error, or the count as it wasdef errors.at(l: Config.Level, more: U32) -> U32:  match l:    case Config.Off{}:      more    case Config.Warn{}:      more    case Config.Error{}:      U32.inc(more)# how many are errorsdef errors(gs: List<&2, F.Graded>) -> U32:  match gs:    case Nil{}:      0    case Con{F.Graded{l, _ff}, rest}:      errors.at(l, errors(rest))# one more below error, or the count as it wasdef warnings.at(l: Config.Level, more: U32) -> U32:  match l:    case Config.Off{}:      U32.inc(more)    case Config.Warn{}:      U32.inc(more)    case Config.Error{}:      more# how many are not errorsdef warnings(gs: List<&2, F.Graded>) -> U32:  match gs:    case Nil{}:      0    case Con{F.Graded{l, _ff}, rest}:      warnings.at(l, warnings(rest))# whether any is an errordef has_error(gs: List<&2, F.Graded>) -> Bool:  match gs:    case Nil{}:      False{}    case Con{F.Graded{l, _ff}, rest}:      +more = has_error(rest)      Bool.or(Config.is_error(l), more)# `1 error`, `2 errors`def count(+n: U32, +what: String) -> String:  U32.show(n) ++ " " ++ what ++ Bool.pick(String, U32.is_eq(n, 1), "", "s")# `clean`, or the countsdef summary(+gs: List<&2, F.Graded>) -> String:  Lazy.stop(String, List.is_empty(&2, F.Graded, gs), "clean",    _u => count(errors(gs), "error") ++ ", " ++ count(warnings(gs), "warning"))# every graded finding as a linedef show_all(gs: List<&2, F.Graded>) -> List<&2, String>:  match gs:    case Nil{}:      Nil{}    case Con{g, rest}:      F.show_graded(g) <> show_all(rest)# `bolt` over a World: every graded finding no mark silences as a line, then# `noqa`'s, then the summary of those, and exit 1 exactly when one is an errordef plan(+world: W.World) -> Plan:  +gs = final.live(world)  Plan{List.append(&2, String, show_all(gs), [summary(gs)]), Bool.pick(U32, has_error(gs), 1, 0)}