Skip to main content

Module engine

Module engine 

Source
Expand description

The scoring engine: walks the normalized crate::ir and computes Cognitive Complexity (SonarSource / G. Ann Campbell) and Cyclomatic Complexity (McCabe).

§Measurement model

Every Node::Function is measured independently: its nesting level starts at 0 at its own boundary, and a structural increment is attributed only to the nearest enclosing function. Nested functions therefore do not inflate the enclosing function’s own score; they are reported as children. A file’s total is module-level code plus every function at every depth (each structural increment counted exactly once).

§Cyclomatic Complexity (McCabe)

Base 1 per function; +1 for each branch (if/else if), ternary, loop, non-default case, catch, and each logical operator (one per extra operand in a Node::Logical).

§Cognitive Complexity (SonarSource)

  • +1 and +nesting bonus for: branch, ternary, switch, loop, catch.
  • +1 flat (no bonus) for: else / else if, labelled jumps, each logical sequence, and recursion (a call to the nearest enclosing function’s name).
  • Nesting increases inside branch/ternary/switch/loop/catch bodies and nested function bodies.

Functions§

analyze
Score a module’s worth of IR (nodes is module-level code) into a FileReport labelled path. parse_errors is carried through verbatim for the adapter’s convenience.