def cwalk

bolt@1.27.0.0 · src/rules/suspicious/concat.bend:347

import bolt@1.27.0.0/src/rules/suspicious/concat.bend as Concat
import Base
import bolt@1.27.0.0/src/finding.bend as F
import bolt@1.27.0.0/src/syntax/lex.bend as Lex
import bolt@1.27.0.0/src/syntax/tree.bend as Tree
import bolt@1.27.0.0/src/rules/calls.bend as Calls
import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy

347# every continuation call's arguments, with the lets in scope
348def cwalk(
349  nn: Tree.Node,
350  +conts: List<&2, String>,
351  +accs: List<&2, String>,
352  +lets: List<&2, Let>,
353  +path: String
354) -> List<&2, F.Finding>:
355  match nn:
356    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, l, c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, rest}}:
357      +me = Bool.and(String.eq(o, "("), List.contains(~String, ~String.eq, conts, t))
358      List.concat(&2, F.Finding, [
359        Lazy.stop(List<&2, F.Finding>, Bool.not(me), [], _u => hits.cont(Calls.args(kids), accs, lets, path, [])),
360        cwalk(kids, conts, accs, lets, path), cwalk(rest, conts, accs, lets, path)])
361    case Tree.NCons{Tree.Group{open, kids, close}, rest}:
362      List.concat(&2, F.Finding, [cwalk(kids, conts, accs, lets, path), cwalk(rest, conts, accs, lets, path)])
363    case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}:
364      List.concat(&2, F.Finding, [cwalk(kids, conts, accs, lets, path), cwalk(body, conts, accs, lets, path),
365        cwalk(rest, conts, accs, after(kind, kids, lets), path)])
366    case Tree.NCons{h, rest}:
367      cwalk(rest, conts, accs, lets, path)
368    case other:
369      Nil{}

Uses (15)

Used by (1)