cognitive_complexity
Finds a procedure whose branching scores above max_complexity (default 25).
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
Shown with these settings:
[lint]
max_complexity = 4
#import "Basic";
sum_above :: (items: [] int, limit: int) -> int {
total := 0;
for items {
if it < 0 continue;
if it > limit {
total += it;
}
}
return total;
}
main :: () {
print("%\n", sum_above(.[3, -1, 8], 2));
}warning[cognitive_complexity]: `sum_above` has a cognitive complexity of 5, past the limit of 4
--> example.jai:3:1
|
3 | sum_above :: (items: [] int, limit: int) -> int {
| ^^^^^^^^^
|
= help: split it into smaller procedures, return early, or name parts of long conditions#import "Basic";
sum_above :: (items: [] int, limit: int) -> int {
total := 0;
for items {
if it > limit && it >= 0 total += it;
}
return total;
}
main :: () {
print("%\n", sum_above(.[3, -1, 8], 2));
}Off by default. Scores how hard a procedure is to follow.