cccc-core 0.1.0

Language-agnostic Cognitive (SonarSource) and Cyclomatic (McCabe) complexity engine over a normalized IR
Documentation
  • Coverage
  • 43.53%
    37 out of 85 items documented1 out of 17 items with examples
  • Size
  • Source code size: 30.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • moznion/cccc
    7 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • moznion

Language-agnostic Cognitive (SonarSource) and Cyclomatic (McCabe) complexity.

This crate computes complexity over a normalized intermediate representation ([ir::Node]) instead of any particular language's AST. A language adapter (such as cccc-typescript) lowers its parse tree into Vec<ir::Node>, and [engine::analyze] scores it. All scoring rules live here, so adding a language means writing an adapter — not reimplementing the metrics.

use cccc_core::ir::Node;
use cccc_core::engine::analyze;

// `if (cond) {}` inside `fn f` — one cognitive point, cyclomatic base 1 + 1.
let f = Node::Function {
    name: "f".into(),
    kind: "function".into(),
    line: 1,
    body: vec![Node::Branch { test: vec![], then: vec![], alternate: None }],
};
let report = analyze("example.ts", &[f], vec![]);
assert_eq!(report.functions[0].cognitive, 1);
assert_eq!(report.functions[0].cyclomatic, 2);