no-self-compare
C / C++C / C++C#JavaJavaScript / TypeScriptKotlinPHPPythonRubysuspiciousno fixdefault: warnjs/biome-recommended
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”class Cases { void f(int a) { if (a == a) { g(); }... }...Configuration
Section titled “Configuration”c: lint: rules: no-self-compare: warn # off, warn (default), errorcpp: lint: rules: no-self-compare: warn # off, warn (default), errorcsharp: lint: rules: no-self-compare: warn # off, warn (default), errorjava: lint: rules: no-self-compare: warn # off, warn (default), errorjs: lint: rules: no-self-compare: warn # off, warn (default), errorkotlin: lint: rules: no-self-compare: warn # off, warn (default), errorphp: lint: rules: no-self-compare: warn # off, warn (default), errorpython: lint: rules: no-self-compare: warn # off, warn (default), errorruby: lint: rules: no-self-compare: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-self-compare |
full |