Skip to content

Commit fd55a85

Browse files
authored
Dump cyclomatic complexity average and cognitive complexity average too (#354)
We were only dumping the total.
1 parent 165467e commit fd55a85

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/output/dump_metrics.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,18 @@ fn dump_cognitive(
113113
last: bool,
114114
stdout: &mut StandardStreamLock,
115115
) -> std::io::Result<()> {
116-
let pref = if last { "`- " } else { "|- " };
116+
let (pref_child, pref) = if last { (" ", "`- ") } else { ("| ", "|- ") };
117117

118118
color!(stdout, Blue);
119119
write!(stdout, "{}{}", prefix, pref)?;
120120

121121
color!(stdout, Green, true);
122-
write!(stdout, "cognitive: ")?;
122+
writeln!(stdout, "cognitive")?;
123123

124-
color!(stdout, White);
125-
writeln!(stdout, "{}", stats.cognitive())
124+
let prefix = format!("{}{}", prefix, pref_child);
125+
126+
dump_value("sum", stats.cognitive(), &prefix, false, stdout)?;
127+
dump_value("average", stats.cognitive_average(), &prefix, true, stdout)
126128
}
127129

128130
fn dump_cyclomatic(
@@ -131,16 +133,18 @@ fn dump_cyclomatic(
131133
last: bool,
132134
stdout: &mut StandardStreamLock,
133135
) -> std::io::Result<()> {
134-
let pref = if last { "`- " } else { "|- " };
136+
let (pref_child, pref) = if last { (" ", "`- ") } else { ("| ", "|- ") };
135137

136138
color!(stdout, Blue);
137139
write!(stdout, "{}{}", prefix, pref)?;
138140

139141
color!(stdout, Green, true);
140-
write!(stdout, "cyclomatic: ")?;
142+
writeln!(stdout, "cyclomatic")?;
141143

142-
color!(stdout, White);
143-
writeln!(stdout, "{}", stats.cyclomatic())
144+
let prefix = format!("{}{}", prefix, pref_child);
145+
146+
dump_value("sum", stats.cyclomatic(), &prefix, false, stdout)?;
147+
dump_value("average", stats.cyclomatic_average(), &prefix, true, stdout)
144148
}
145149

146150
fn dump_halstead(

0 commit comments

Comments
 (0)