scute_core/code_complexity/mod.rs
1//! Cognitive complexity scoring for Rust functions.
2//!
3//! Scores each function based on how hard it is to understand, following
4//! [G. Ann Campbell's cognitive complexity spec](https://www.sonarsource.com/docs/CognitiveComplexity.pdf).
5//! Six cognitive drivers contribute to the score: flow breaks, nesting,
6//! else branches, boolean logic sequences, recursion, and labeled jumps.
7//!
8//! Nesting is the main multiplier: an `if` inside a `for` inside a `match`
9//! costs `1 + depth`, not just 1. Else-if chains are scored flat. Closures
10//! inherit the parent's nesting level.
11//!
12//! # Usage
13//!
14//! ```no_run
15//! use std::path::PathBuf;
16//! use scute_core::code_complexity::{self, Definition};
17//!
18//! let results = code_complexity::check(
19//! &[PathBuf::from("src/")], // files or directories to check
20//! &Definition::default(), // warn: 5, fail: 10
21//! );
22//! ```
23//!
24//! Each function produces one [`Evaluation`](crate::Evaluation) with per-line
25//! [`Evidence`](crate::Evidence) entries explaining what drives the score.
26
27mod check;
28mod score;
29
30pub use check::{CHECK_NAME, Definition, check};