complexity/cognitive.bend relies on unsafe/foreign
raw source on the hub · import bend-lint-pack@0.1.1.0/complexity/cognitive.bend as Cognitive
complexity/cognitive: warn when a def is harder to read than max (default 15).
Nesting-weighted, after SonarSource's cognitive complexity, with Bend's only branch, match:
each match adds 1, plus 1 for every match it sits inside (an arm body of an outer match).
Arms of one match do not nest in each other.
Bend checks a match into a chain of Mat nodes, one per tested constructor: a Mat's first child is
the arm body, and its second is the rest of the chain (another Mat) or the _ arm (a Lam).
This rule walks that tree and starts a match only at a Mat that is not the rest of a chain.
A match on several values at once (match a b:) is checked as nested tests and counts as such.
Options: max (default 15).
3 imports
import Base import ../vendor/lint.bend as Lint import ../common.bend as Common
Definitions
def id source · line 16 · raw
String
def facts source · line 19 · raw
0x7294c9a1db4be6346e88202032984e02/vendor/lint.Want
def walk.all source · line 33 · raw
@cs:List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> @+depth:U32 -> @+chain:Bool -> @total:U32 -> IO(U32)
Each of cs the same way.
def walk.arms source · line 41 · raw
@cs:List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> @+depth:U32 -> @+first:Bool -> @total:U32 -> IO(U32)
The children of a Mat: the first is an arm body, one level down; the others continue the chain.
def walk.step source · line 53 · raw
@is_mat:Bool -> @is_ann:Bool -> @children:List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> @+depth:U32 -> @+chain:Bool -> @total:U32 -> IO(U32)
def walk.shape source · line 74 · raw
@s:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Shape -> @depth:U32 -> @chain:Bool -> @total:U32 -> IO(U32)
def score.of source · line 79 · raw
@body:Maybe<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node> -> IO(U32)
def message source · line 86 · raw
@+name:String -> @score:U32 -> @max:U32 -> String
def judge source · line 89 · 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 109 · raw
@input:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Input -> IO(List<&2, 0x7294c9a1db4be6346e88202032984e02/vendor/lint.Diag>)
def main source · line 116 · raw
IO(Unit)
Unsafe
unsafe walk source · line 27 · raw
@n:0x7294c9a1db4be6346e88202032984e02/vendor/lint.Node -> @depth:U32 -> @chain:Bool -> @total:U32 -> IO(U32)
The tree walk. depth is the number of matches around the node, chain says the node is the
rest of a match chain (reached from its Mat), and total is the score so far.
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.