A value is converted to a boolean where it is tested as one already

tx0/ts:redundant-boolean-castrecommendedwarningstyle

What it finds

if (!!value) and while (Boolean(next)) convert a value to a boolean where it is tested for truth anyway, so the conversion changes nothing. The same holds for the operand of !.

The conversions are !!x and a call of the global Boolean with one argument; the places are the conditions of if, while, do and for, the test of a conditional expression and the operand of !, through parentheses. The fix, which is safe, keeps only the converted value.

From the rule's source, redundant_boolean_cast.rs.

Example from the rule's tests
function test(value: unknown, items: unknown[]) {  if (!!value) {tx0 reports: conversion to boolean is redundant    return 1;  }  while (Boolean(items.pop())) {tx0 reports: conversion to boolean is redundant    items.length;  }  const kept = !!value;  const negated = !Boolean(value);tx0 reports: conversion to boolean is redundant  return kept ? 2 : negated;}function shadowed(Boolean: (x: unknown) => boolean, v: unknown) {  if (Boolean(v)) {    return 1;  }  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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:redundant-boolean-cast" = "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:redundant-boolean-cast] reason="..."

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