Skip to main content

Module code_complexity

Module code_complexity 

Source
Expand description

Cognitive complexity scoring for Rust functions.

Scores each function based on how hard it is to understand, following G. Ann Campbell’s cognitive complexity spec. Six cognitive drivers contribute to the score: flow breaks, nesting, else branches, boolean logic sequences, recursion, and labeled jumps.

Nesting is the main multiplier: an if inside a for inside a match costs 1 + depth, not just 1. Else-if chains are scored flat. Closures inherit the parent’s nesting level.

§Usage

use std::path::PathBuf;
use scute_core::code_complexity::{self, Definition};

let results = code_complexity::check(
    &[PathBuf::from("src/")],  // files or directories to check
    &Definition::default(),    // warn: 5, fail: 10
);

Each function produces one Evaluation with per-line Evidence entries explaining what drives the score.

Structs§

Definition
Configuration for the code complexity check.

Constants§

CHECK_NAME

Functions§

check
Score cognitive complexity for every function in the given paths.