1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! The language-agnostic intermediate representation (IR) that the complexity
//! engine scores.
//!
//! A language adapter (e.g. `cccc-typescript`) lowers its native AST into a
//! `Vec<Node>` describing only the constructs that affect Cognitive / Cyclomatic
//! Complexity — branches, loops, switches, exception handlers, logical-operator
//! sequences, function boundaries, and calls. Everything else collapses into
//! [`Node::Group`], which is a transparent container the engine simply recurses
//! into. All scoring rules live in [`crate::engine`]; the IR carries no scores.
//!
//! The top level handed to the engine is itself a `&[Node]`, representing
//! module-level code; the engine scores it under an implicit module frame.
/// A logical operator, normalized across languages.
///
/// The adapter is responsible for folding a run of like operators into a single
/// [`Node::Logical`] (e.g. `a && b && c` is one `Logical` with three operands);
/// the engine counts one cognitive point per `Logical` node.
/// One arm of a [`Node::Switch`].
/// A node of the normalized complexity IR.
///
/// Fields that hold sub-expressions or sub-statements are `Vec<Node>` so the
/// adapter can drop irrelevant detail and the engine can recurse uniformly.