An if statement without else is the only statement of another

tx0/ts:collapsible-ifstrictwarningstyle

What it finds

if (a) { if (b) { ... } }, where neither statement has an else, runs its body only when both conditions hold, which if (a && b) says in one place with one level of nesting less.

The inner if must be the only statement of the outer one, directly or as the only statement of its block.

From the rule's source, collapsible_if.rs.

Example from the rule's tests
function check(a: boolean, b: boolean) {  if (a) {    if (b) {tx0 reports: can be merged with the enclosing one      return 1;    }  }  if (a)    if (b) return 2;tx0 reports: can be merged with the enclosing one  if (a) {    if (b) {      return 3;    } else {      return 4;    }  }  if (a) {    if (b) {      return 5;    }  } else {    return 6;  }  if (a) {    if (b) {      return 7;    }    return 8;  }  return 0;}
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:collapsible-if" = "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:collapsible-if] reason="..."

tx0 explain tx0/ts:collapsible-if shows the same in the terminal. Found a false positive? Report it.