Skip to content

no-useless-expression

Reports an expression statement whose value is thrown away and that has no effect of its own: a name, a literal, a member access or an operator expression (x + y;, x.y;, -x;, x ? y : z;). Calls, assignments, delete and void are not reported; a directive such as "use strict" is, as it is a string. What counts as pure is the #pure tag of the language’s grammar: Python’s table has names, literals, member accesses and list, set and dict displays, so x + 1, x == 2 and -x are not reported there. Off by default.

The statement is evaluated and dropped, so it does nothing. It is typically a line that was meant to be a call (a missing ()), a comparison written where an assignment was meant, or what is left of a deleted line.

To fix, delete it, or write the call or the assignment it was meant to be.

Reported
a + b;
f();
a && f();
x = 1;
js:
lint:
rules:
no-useless-expression: warn # off (default), warn, error
python:
lint:
rules:
no-useless-expression: warn # off (default), warn, error

Enabled by the presets: js/eslint-recommended, js/typescript-eslint-recommended, js/oxlint, python/ruff.

Suppress one line with sudsy-disable-next-line no-useless-expression in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint no-unused-expressions partial the options keep their defaults
ruff B018 full
typescript-eslint no-unused-expressions partial the options keep their defaults