# no-identical-expressions

Rule `sonarjs/no-identical-expressions`. Identical expressions should not be used on both sides of a binary operator

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1281 by reach, #582 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-identical-expressions` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1764/) |

## Code examples

### Incorrect: the rule reports this

```js
if (a == b && a == b) { // if the first one is true, the second one is too
  doX();
}
if (a > a) { // always false
  doW();
}

var j = 5 / 5; //always 1
var k = 5 - 5; //always 0
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-identical-expressions": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-identical-conditions](https://lintradar.dev/rules/sonarjs/no-identical-conditions.md): "if/else if" chains and "switch" cases should not have the same condition
- [sonarjs/no-identical-functions](https://lintradar.dev/rules/sonarjs/no-identical-functions.md): Functions should not have identical implementations
- [sonarjs/no-hook-setter-in-body](https://lintradar.dev/rules/sonarjs/no-hook-setter-in-body.md): React's useState hook should not be used directly in the render function or body of a component
- [sonarjs/no-ignored-exceptions](https://lintradar.dev/rules/sonarjs/no-ignored-exceptions.md): Exceptions should not be ignored
- [sonarjs/no-hardcoded-secrets](https://lintradar.dev/rules/sonarjs/no-hardcoded-secrets.md): Secrets should not be hard-coded
- [sonarjs/no-ignored-return](https://lintradar.dev/rules/sonarjs/no-ignored-return.md): Return values from functions without side effects should not be ignored

---

Web page: https://lintradar.dev/rules/sonarjs/no-identical-expressions. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
