if_not_else
Finds an if or ifx with a negated condition and an else.
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
main :: () {
ready := false;
if !ready {
print("waiting\n");
} else {
print("going\n");
}
}warning[if_not_else]: `if !ready` is negated, with an `else`
--> example.jai:6:5
|
6 | if !ready {
| ^^^^^^^^^
|
help: test `ready` first and swap the branches
|
6 ~ if ready {
7 ~ print("going\n");
9 ~ print("waiting\n");
|#import "Basic";
main :: () {
ready := false;
if ready {
print("going\n");
} else {
print("waiting\n");
}
}Off by default, since putting the exceptional or shorter branch first is often right.