A condition tests the promise of an async call, which is always true
What it finds
if (isAllowed(user)) where isAllowed is an async function: a promise is an object, and every object is true, so the condition holds whatever the function decides. await was left out.
Conditions of if, loops and ?:, operands of !, && and || in them, are checked; the call must certainly return a promise, as a call of an async function or method of this file that is not reassigned does.
From the rule's source, promise_as_condition.rs.
async function isAllowed(user: string) { return user !== "";}async function check(user: string) { if (isAllowed(user)) {tx0 reports: this async call gives a promise, which is always true here return 1; } while (!isAllowed(user) && user) {tx0 reports: this async call gives a promise break; } const label = isAllowed(user) ? "yes" : "no";tx0 reports: this async call gives a promise if (await isAllowed(user)) { return 2; } return label;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/ts:promise-as-condition" = "off"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:promise-as-condition] reason="..."tx0 explain tx0/ts:promise-as-condition shows the same in the terminal. Found a false positive? Report it.