# no-unsafe-negation

Rule `eslint/no-unsafe-negation`. Disallow negating the left operand of relational operators

- Source: eslint
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 277.5M weekly downloads of presets that enable it
- Trend: +45.2% last quarter
- Rank: #24 by reach, #905 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-unsafe-negation` | yes | suggestion | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-unsafe-negation) |
| Oxlint | `no-unsafe-negation` | yes | safe | plugin `eslint`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.html) |
| Biome | `suspicious/noUnsafeNegation` | yes | unsafe | group suspicious, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/no-unsafe-negation/) |

## Code examples

### Incorrect: the rule reports this

```js
if (!key in object) {
    // operator precedence makes it equivalent to (!key) in object
    // and type conversion makes it equivalent to (key ? "false" : "true") in object
}

if (!obj instanceof Ctor) {
    // operator precedence makes it equivalent to (!obj) instanceof Ctor
    // and it equivalent to always false since boolean values are not objects.
}
```

```js
if (!(foo) in object) {
    // this is not an allowed exception
}
```

### Correct: the rule accepts this

```js
if (!(key in object)) {
    // key is not in object
}

if (!(obj instanceof Ctor)) {
    // obj is not an instance of Ctor
}
```

```js
if ((!foo) in object) {
    // allowed, because the negation is explicitly wrapped in parentheses
    // it is equivalent to (foo ? "false" : "true") in object
    // this is allowed as an exception for rare situations when that is the intended meaning
}

if(("" + !foo) in object) {
    // you can also make the intention more explicit, with type conversion
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "no-unsafe-negation": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-unsafe-negation": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noUnsafeNegation": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [ESLint recommended](https://lintradar.dev/presets/eslint-recommended.md) | ESLint | `@eslint/js` | 64 | 178.8M | +25.9% |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Create React App](https://lintradar.dev/presets/react-app.md) | ESLint | `eslint-config-react-app` | 109 | 4.1M | +4.3% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [JavaScript Standard Style](https://lintradar.dev/presets/standard.md) | ESLint | `eslint-config-standard` | 161 | 3.1M | +12.9% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [eslint/no-irregular-whitespace](https://lintradar.dev/rules/eslint/no-irregular-whitespace.md): Disallow irregular whitespace
- [eslint/no-async-promise-executor](https://lintradar.dev/rules/eslint/no-async-promise-executor.md): Disallow using an async function as a Promise executor
- [eslint/no-this-before-super](https://lintradar.dev/rules/eslint/no-this-before-super.md): Disallow `this`/`super` before calling `super()` in constructors
- [eslint/no-compare-neg-zero](https://lintradar.dev/rules/eslint/no-compare-neg-zero.md): Disallow comparing against `-0`
- [eslint/no-extra-boolean-cast](https://lintradar.dev/rules/eslint/no-extra-boolean-cast.md): Disallow unnecessary boolean casts
- [eslint/no-misleading-character-class](https://lintradar.dev/rules/eslint/no-misleading-character-class.md): Disallow characters which are made with multiple code points in character class syntax

---

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