The position from indexOf is compared only to learn whether an element is present

tx0/ts:index-of-existencestrictwarningstyle

What it finds

list.indexOf(item) !== -1 asks for a position only to compare it with the value that means "absent", where list.includes(item) asks the question directly. The comparisons with -1, >= 0 and < 0 are easy to get subtly wrong, as with > 0.

Reported are calls of indexOf or lastIndexOf compared with -1 by ===, !==, ==, != or >, or with 0 by >= or <. There is no fix: includes also finds NaN, and the receiver may be an object other than an array or string.

From the rule's source, index_of_existence.rs.

Example from the rule's tests
export function has(list: string[], item: string) {  const a = list.indexOf(item) !== -1;tx0 reports: includes asks directly  const b = list.indexOf(item) >= 0;tx0 reports: includes asks directly  const c = list.indexOf(item) === 2;  return [a, b, c];}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:index-of-existence" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:index-of-existence] reason="..."

tx0 explain tx0/ts:index-of-existence shows the same in the terminal. Found a false positive? Report it.