# no-negated-condition

> Disallow negated conditions in `if`/`else` and in ternaries

When both branches are there, a negated condition makes the `else` a double negative: "if not logged in .. otherwise ..". Swapping the branches removes the negation and says the same thing.

The rule looks at conditions of the form `!x`, `a != b` and `a !== b`. An `if` without `else` is fine, and so is one followed by `else if`.

With an oxlint config, `--fix` removes the negation and swaps the branches.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-negated-condition" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
if (!user) {
  redirect("/login");
} else {
  render(user);
}
```

{/* bad */}
```js
const label = count !== 1 ? "items" : "item";
```

Not reported:

{/* good */}
```js
if (user) {
  render(user);
} else {
  redirect("/login");
}

const label = count === 1 ? "item" : "items";
```

{/* good */}
```js
if (!user) {
  redirect("/login");
}

if (!user) {
  redirect("/login");
} else if (user.isAdmin) {
  renderAdmin(user);
}
```
