1 # rule hole: a TODO hole left in code, the one bend counts when it prints 2 # `SOME PROOFS FAIL` then "Error: 1 TODO found." or "Error: N TODOs found." 3 # and exits 1 (bend 2.0.34): a `?` and then the name `TODO`, with any spaces, newlines or comments 4 # between them (`?TODO`, `? TODO`). `?todo`, `?TODO_later` and `?TODO.x` are 5 # other names, which bend reports as a type error, not as a TODO, and they are 6 # not reported here. The finding spans `?` through `TODO` when both sit on one 7 # line, and the `?` alone when `TODO` is on a later line. LAWS.bend is exempt: 8 # by convention its laws are open claims, filled by PROOF.bend beside it. 9 import Base 10 import ../../paths.bend as Paths 11 import ../../src.bend as Src 12 import ../../finding.bend as F 13 import ../../syntax/lex.bend as Lex 14 import ../../lazy/lazy.bend as Lazy 15 import ../calls.bend as Calls 16 17 # True when the first token past spaces, newlines and comments is `TODO` 18 def check.todo(toks: List<&2, Lex.Tok>) -> Bool: 19 match toks: 20 case Con{Lex.Tok{+k, +t, l, c}, rest}: 21 Lazy.stop(Bool, Lex.significant(k), Bool.and(Calls.kind.upper(k), String.eq(t, "TODO")), _u => check.todo(rest)) 22 case Nil{}: 23 False{} 24 25 # the width of the hole a `?` at line, col starts: through the next token 26 # past spaces, newlines and comments when it sits on the same line, else 1 27 def check.width(toks: List<&2, Lex.Tok>, +line: U32, +col: U32) -> U32: 28 match toks: 29 case Con{Lex.Tok{k, t, +l, +c}, rest}: 30 Lazy.stop(U32, Lex.significant(k), Bool.pick(U32, U32.is_eq(l, line), U32.add(U32.sub(c, col), 4), 1), 31 _u => check.width(rest, line, col)) 32 case Nil{}: 33 1 34 35 def check.go(toks: List<&2, Lex.Tok>, +path: String) -> List<&2, F.Finding>: 36 match toks: 37 case Con{Lex.Tok{k, +q, +l, +c}, +rest}: 38 +more = check.go(rest, path) 39 Lazy.stop(List<&2, F.Finding>, Bool.not(Bool.and(Calls.kind.oper(k), Lazy.and_then(String.eq(q, "?"), 40 _u => check.todo(rest)))), more, 41 _u => F.Finding{path, l, c, check.width(rest, l, c), "hole", "This ?TODO hole is still unfilled."} <> more) 42 case Nil{}: 43 Nil{} 44 45 def check.on(toks: List<&2, Lex.Tok>, +path: String) -> List<&2, F.Finding>: 46 Lazy.stop(List<&2, F.Finding>, Paths.is_laws(path), [], _u => check.go(toks, path)) 47 48 # the rule 49 def check(ss: Src.Src) -> List<&2, F.Finding>: 50 Src.Src{path, text, toks, tree, bound, items} = ss 51 check.on(toks, path)