complexity/cyclomatic.bend relies on unsafe/foreign
raw source on the hub · import bend-lint-pack@0.1.1.0/complexity/cyclomatic.bend as Cyclomatic
complexity/cyclomatic: warn when a def has more than max independent paths (default 10).
Bend has no loops or if; every branch is a match. Bend checks a match into one Mat node per
tested constructor, closed by an Efq node when the arms are exhaustive. The closing test is not a
decision (its failure is impossible), so
complexity = 1 + (Mat nodes - Efq nodes)
Three arms give 3; two arms and a _ give 2 + 1 = 3; a single-constructor destructuring gives 1.
A match on several values at once (match a b:) is checked as nested tests and counts as such.
Options: max (default 10).
3 imports
import Base import ../vendor/lint.bend as Lint import ../common.bend as Common
Types
type Tally source · line 23 · raw
Data
Node kinds seen under a def.
Tally@mats:U32 -> @efqs:U32 -> Tally
Definitions
def id source · line 16 · raw
String
def facts source · line 19 · raw
0x7294c9a1db4be6346e88202032984e02/vendor/lint.Want
def bump.kind source · line 26 · raw
@+kind:String -> @t:Tally -> Tally
def walk.all source · line 49 · raw
@cs:List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> @t:Tally -> IO(Tally)
def walk.shape source · line 56 · raw
@s:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Shape -> @t:Tally -> IO(Tally)
def complexity source · line 62 · raw
@t:Tally -> U32
1 + Mat - Efq; never below 1.
def score.of source · line 67 · raw
@body:Maybe<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> IO(U32)
def message source · line 74 · raw
@+name:String -> @score:U32 -> @max:U32 -> String
def judge source · line 77 · raw
@+max:U32 -> @seen:List<&2, 0x7294c9a1db4be6346e88202032984e02/common.Seen> -> @out:List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Diag> -> IO(List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Diag>)
def run source · line 97 · raw
@input:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Input -> IO(List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Diag>)
def main source · line 104 · raw
IO(Unit)
Unsafe
unsafe walk source · line 44 · raw
@n:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node -> @t:Tally -> IO(Tally)
The checked body is a finite tree, so this terminates; Bend cannot see that (nodes are handles, not smaller parts), hence @unsafe, as bend-lint's own fold_facts.