src/rules/suspicious/fromrev.bend checks
raw source on the hub · import bolt@1.47.0.0/src/rules/suspicious/fromrev.bend as Fromrev
rule fromrev: a String read off a reversed list: among the significant
tokens (spaces, newlines and comments dropped), four tokens right after one
another whose texts are String.from_list, (, List.reverse and (;
one finding, on the String.from_list token, for each such run, and
nothing else. Anything between them, another ( included
(String.from_list((List.reverse(..)))), is not the shape, and neither is
List.reverse.go. A buffer of chars consed on the front, then reversed
and read into a String, walks the buffer twice and builds a list only to
throw it away (and String.from_list, not a tail call, runs the JS lane out
of stack on a long buffer): fold the buffer onto a String with SCon in one
pass, go(t, SCon{h, acc}) from SNil{} (src/rchars.bend). A LAWS.bend
or a PROOF.bend, which never runs, is exempt.
8 imports
import Base import ../../src.bend as Src import ../../paths.bend as Paths import ../../role.bend as Role import ../../lazy/lazy.bend as Lazy import ../../finding.bend as F import ../../syntax/lex.bend as Lex import ../tokens.bend as T
Definitions
def shape source · line 23 · raw
@+tt:String -> @+aa:String -> @+bb:String -> @+dd:String -> Bool
are the four texts String.from_list, (, List.reverse and (?
def at source · line 28 · raw
@+tt:String -> @toks:List<&2, 0x3526f2b0a14a45014fd9ab9c49ecc717/src/syntax/lex.Tok> -> Bool
a token of text tt, then these: do the four open the shape?
def walk source · line 36 · raw
@toks:List<&2, 0x3526f2b0a14a45014fd9ab9c49ecc717/src/syntax/lex.Tok> -> @+path:String -> List<&2, 0x3526f2b0a14a45014fd9ab9c49ecc717/src/finding.Finding>
every run of the shape among the tokens, in order
def check source · line 48 · raw
@ss:0x3526f2b0a14a45014fd9ab9c49ecc717/src/src.Src -> List<&2, 0x3526f2b0a14a45014fd9ab9c49ecc717/src/finding.Finding>
the rule
def check.role source · line 54 · raw
@rr:0x3526f2b0a14a45014fd9ab9c49ecc717/src/role.Role -> @ss:0x3526f2b0a14a45014fd9ab9c49ecc717/src/src.Src -> List<&2, 0x3526f2b0a14a45014fd9ab9c49ecc717/src/finding.Finding>
the rule, told the file's role (src/role.bend): a law or proof file is skipped