A loop with an always-true condition has no break, return or throw
What it finds
while (true) { poll(); } with no way out: a loop whose condition is always true and whose body has no break, return or throw, and calls no function named for not returning, never ends and blocks the thread. In a generator or async function, yield and await hand control back, so such loops are left alone there.
Reported are while (true), do ... while (true) and for (;;) loops, also with 1 as the condition.
From the rule's source, endless_loop.rs.
export function spin(poll: () => boolean) { while (true) {tx0 reports: this loop never ends: nothing leaves it poll(); }}export function wait(poll: () => boolean) { while (true) { if (poll()) { break; } } for (;;) { if (poll()) { return; } }}export async function tick(poll: () => Promise<void>) { while (true) { await poll(); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:endless-loop" = "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:endless-loop] reason="..."tx0 explain tx0/ts:endless-loop shows the same in the terminal. Found a false positive? Report it.