An if statement returns true in one branch and false in the other

tx0/ts:boolean-return-wrappedstrictwarningstyle

What it finds

if (c) { return true; } else { return false; } spends five lines on returning the truth of c, which return c; says directly when c is a boolean, or return Boolean(c); otherwise.

Both forms are found: with an else, and with the second return as the statement right after the if. Each branch must be a single return of true or false, directly or as the only statement of a block, and the two values must differ.

From the rule's source, boolean_return_wrapped.rs.

Example from the rule's tests
function isBig(n: number) {  if (n > 10) {tx0 reports: return the condition    return true;  } else {    return false;  }}function isSmall(n: number) {  if (n > 10) return false;tx0 reports: return the negated condition  return true;}function other(n: number) {  if (n > 10) {    return true;  }  return n > 5;}
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:boolean-return-wrapped" = "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:boolean-return-wrapped] reason="..."

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