An if-else-if chain has no final else
What it finds
A chain of if and else if that ends without an else does nothing when no condition holds, and a reader cannot tell whether that case was considered. A final else, even one that only throws or holds a comment, says so.
The last if of a chain with at least one else if is reported. A plain if without else is not a chain and is left alone.
From the rule's source, else_if_without_else.rs.
function kind(n: number) { if (n > 10) { return "big"; } else if (n > 5) {tx0 reports: this if-else-if chain ends without else return "medium"; } if (n > 1) { return "some"; } else if (n > 0) { return "one"; } else { return "none"; }} 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:
[rules]
"tx0/ts:else-if-without-else" = "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:else-if-without-else] reason="..."tx0 explain tx0/ts:else-if-without-else shows the same in the terminal. Found a false positive? Report it.