> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-self-compare

[Added in v0.5.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.0)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-self-compare': 'error',
    },
  },
]);
```

## Rule Details

Disallows comparing a value to itself using any of the equality or relational operators (`===`, `==`, `!==`, `!=`, `>`, `<`, `>=`, `<=`). Such a comparison is typically a typo (the programmer likely meant a different operand) and is either always true, always false, or always `NaN`-sensitive, so the check is pointless.

Examples of **incorrect** code for this rule:

```javascript
var x = 10;
if (x === x) {
}

if (x !== x) {
}

if (foo.bar().baz.qux >= foo.bar().baz.qux) {
}
```

Examples of **correct** code for this rule:

```javascript
var x = 10;
var y = 10;
if (x === y) {
}

if (foo.bar.baz === foo.bar.qux) {
}

class C {
  #field;
  foo() {
    // Property access via private identifier and bracket string literal
    // are structurally distinct and allowed.
    return this.#field === this["#field"];
  }
}
```

## Original Documentation

- [ESLint: no-self-compare](https://eslint.org/docs/latest/rules/no-self-compare)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-self-compare.js)
