Skip to content

no-self-compare

Reports an equality or comparison whose two sides are the same tokens (x === x, x < x). x != x used as a test for NaN is reported too. Two calls (f() === f()) count as the same tokens and are reported.

For a value the result is the same every time (except for NaN), so the test is dead or a typing error: the author compared a variable with itself instead of with another one.

To fix, compare with the right value; to test for NaN, use isNaN or the language’s own check.

Reported
class Cases {
void f(int a) {
if (a == a) { g(); }
...
}
...
c:
lint:
rules:
no-self-compare: warn # off, warn (default), error
cpp:
lint:
rules:
no-self-compare: warn # off, warn (default), error
csharp:
lint:
rules:
no-self-compare: warn # off, warn (default), error
java:
lint:
rules:
no-self-compare: warn # off, warn (default), error
js:
lint:
rules:
no-self-compare: warn # off, warn (default), error
kotlin:
lint:
rules:
no-self-compare: warn # off, warn (default), error
php:
lint:
rules:
no-self-compare: warn # off, warn (default), error
python:
lint:
rules:
no-self-compare: warn # off, warn (default), error
ruby:
lint:
rules:
no-self-compare: warn # off, warn (default), error

Enabled by the presets: js/biome-recommended.

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

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-self-compare full