An else follows a branch that always leaves, so it only adds nesting

tx0/ts:else-after-returnstrictwarningstyle

What it finds

if (x) { return a; } else { b(); } nests the rest of the function in an else that can only run when the if branch did not leave: the code after the if would run in exactly the same cases without the extra level.

Reported are else branches, not else if, of if statements whose branch always ends with return, throw, break or continue, when the if is not itself the else of another, where removing the else would change the chain.

From the rule's source, else_after_return.rs.

Example from the rule's tests
export function sign(n: number) {  if (n < 0) {    return -1;  } else {tx0 reports: this else only adds nesting    console.log(n);  }  if (n > 0) {    console.log(n);  } else {    return 0;  }  if (n === 1) {    return 1;  } else if (n === 2) {    return 2;  }  return 3;}
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:else-after-return" = "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-after-return] reason="..."

tx0 explain tx0/ts:else-after-return shows the same in the terminal. Found a false positive? Report it.