excessive_nesting
Finds blocks nested deeper than max_nesting (default 6).
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
count_sums :: (a: [] int, b: [] int, c: [] int, target: int) -> int {
hits := 0;
for x: a {
if x > 0 {
for y: b {
if y > 0 {
for z: c {
if z > 0 {
if x + y + z == target {
hits += 1;
}
}
}
}
}
}
}
return hits;
}
main :: () {
print("%\n", count_sums(.[1, 2], .[3, 4], .[5, 6], 9));
}warning[excessive_nesting]: this block is nested 7 deep, past the limit of 6
--> example.jai:12:52
|
12 | if x + y + z == target {
| ^
|
= help: return or `continue` early, or move the inner part into its own procedure#import "Basic";
count_sums :: (a: [] int, b: [] int, c: [] int, target: int) -> int {
hits := 0;
for x: a {
if x <= 0 continue;
for y: b {
if y <= 0 continue;
for z: c {
if z <= 0 continue;
if x + y + z == target hits += 1;
}
}
}
return hits;
}
main :: () {
print("%\n", count_sums(.[1, 2], .[3, 4], .[5, 6], 9));
}Off by default. A level is a braced block or a switch; else if chains and #if add none.