~/bend-docscommunity

src/rules/suspicious/fromrev.bend checks

raw source on the hub · import bolt@1.65.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

@+t:String -> @+a:String -> @+b:String -> @+d:String -> Bool

are the four texts String.from_list, (, List.reverse and (?

def at source · line 28 · raw

@+t:String -> @toks:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> Bool

a token of text t, then these: do the four open the shape?

def walk source · line 36 · raw

@toks:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> @+path:String -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>

every run of the shape among the tokens, in order

def check source · line 48 · raw

@s:0xdaa3743e782ddca8ff3f355948b1d747/src/src.Src -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>

the rule

def check.role source · line 54 · raw

@r:0xdaa3743e782ddca8ff3f355948b1d747/src/role.Role -> @s:0xdaa3743e782ddca8ff3f355948b1d747/src/src.Src -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>

the rule, told the file's role (src/role.bend): a law or proof file is skipped