A for loop has a condition but neither initializer nor update

tx0/ts:for-as-whilestrictwarningstyle

What it finds

for (; ready(); ) { ... } is a while loop in the clothes of a for: with neither an initializer nor an update, the two semicolons only make the reader look for parts that are not there.

Reported are for statements with a condition but no initializer and no update. A for (;;) without condition is the usual way to write an endless loop and is left alone. The fix, which is safe, writes while (condition).

From the rule's source, for_as_while.rs.

Example from the rule's tests
export function drain(queue: number[]) {  for (; queue.length > 0; ) {tx0 reports: this for has only a condition    queue.pop();  }  for (;;) {    break;  }  for (let i = 0; i < 3; ) {    i++;  }}
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:for-as-while" = "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:for-as-while] reason="..."

tx0 explain tx0/ts:for-as-while shows the same in the terminal. Found a false positive? Report it.