~/bend-docscommunity

src/rules/suspicious/concat.bend fails

raw source on the hub · import 0xde9bb08f7de298b03207fb5797ede9a5/src/rules/suspicious/concat.bend as Concat

rule concat: a def passes itself a parameter grown at the end, p ++ x or List.append(.., p, ys) (String.append(p, ..) too), as the argument in p's own position, the slot it carries; p grown into another slot is not a finding. The argument is that append written in place, inside any number of parentheses ((p ++ x)), or a lone name read from a let: the nearest q = .. or +q = .. of that name before the call in its block or an enclosing one, whose right side is such an append (a later let of the name shadows it; other binders, a typed or destructuring let and a do-bind do not count). A String and a List are cons lists, so appending copies all of p: the loop is quadratic, with right output (night-train's text step cost three times the render; rootagi's JSON stringify). Prepend (x <> acc) and reverse once at the end, build with h <> go(t), or gather pieces and join them once.

7 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../calls.bend as Calls
import ../../lazy/lazy.bend as Lazy