An expression statement has no effect
What it finds
x === 1;, count + 1;, !done;: an expression statement whose value is computed and thrown away, with no effect. Usually an assignment or a return was meant, as x = 1 or return count + 1.
Reported are comparisons, arithmetic and other binary operators, unary operators other than void, delete, ++ and --, this, literals and templates, as long as nothing in them calls, assigns or creates anything. Logical operators are reported only when their right side has no effect either, since ready && start() is a common if statement. Member accesses are left alone, as reading a property can run a getter on purpose, and so are bare names, a common way to mark a variable as used or to check that a switch is exhaustive, and so are the string directives such as "use strict" at the start of a file or function. Files with syntax errors are skipped, since a syntax the parser does not know can leave pieces that look like expressions.
From the rule's source, useless_expression.rs.
function check(x: number, done: boolean, ready: boolean) { "use strict"; x === 1;tx0 reports: this expression has no effect x + 1;tx0 reports: this expression has no effect !done;tx0 reports: this expression has no effect ready && start(); void x; x++; return x;}function start() {} 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:
[rules]
"tx0/ts:useless-expression" = "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:useless-expression] reason="..."tx0 explain tx0/ts:useless-expression shows the same in the terminal. Found a false positive? Report it.