-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathcomplexity.sh
executable file
·30 lines (25 loc) · 1.19 KB
/
complexity.sh
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
#!/bin/bash
meson setup _complexity --native-file llvm.ini
cd _complexity
run-clang-tidy -quiet \
-config="{Checks: 'readability-function-cognitive-complexity', CheckOptions: [{key: readability-function-cognitive-complexity.Threshold, value: 25}, {key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: False}]}" \
2>/dev/null | \
grep warning | grep "cognitive complexity" > complexity.log || :
complexity=0
complex_functions=0
while read -r log; do
file=$(echo $log | awk -F":" '{ print $1 }')
line=$(echo $log | awk -F":" '{ print $2 }')
function=$(echo $log | awk -F"function" '{ print $2 }' | awk '{ print $1 }' | sed "s/'//g")
score=$(echo $log | awk -F"cognitive complexity of" '{ print $2 }' | awk '{ print $1 }')
echo "Complex function found: $file:$line $function(), complexity score: $score"
complexity=$(( complexity + score ))
(( complex_functions++ )) || :
done < complexity.log
mv complexity.log ..
cd ..
rm -rf _complexity
echo "Found $complex_functions complex functions"
echo "Final complexity sum of complex functions: $complexity"
echo "Functions: $complex_functions" >> complexity.log
echo "Sum: $complexity" >> complexity.log