Esc

manual_array_find

Finds a loop that searches an array and breaks with a found flag or index, which array_find does.

Category complexity, warn by default.

Example
#import "Basic";

has :: (names: [] string, wanted: string) -> bool {
    found := false;

    for names {
        if it == wanted {
            found = true;
            break;
        }
    }

    return found;
}

main :: () {
    print("%\n", has(.["ada", "grace"], "grace"));
}
Diagnostic
warning[manual_array_find]: this loop looks for `wanted` in `names` by hand
  --> example.jai:6:5
   |
 6 |     for names {
   |     ^^^^^^^^^
   |
   = help: `array_find(names, wanted)` returns whether it was found, and the index after that
   = note: `manual_array_find` is `warn` by default
Fixed
#import "Basic";

has :: (names: [] string, wanted: string) -> bool {
    found := array_find(names, wanted);
    return found;
}

main :: () {
    print("%\n", has(.["ada", "grace"], "grace"));
}

Fires on a for over an array whose body is one if without an else: it compares the loop's value (it, or the name given to.