# @typescript-eslint/no-unnecessary-boolean-literal-compare

> Disallow comparing a boolean with `true` or `false`

If a value is a `boolean`, `value === true` is the same as `value`, and `value === false` is the same as `!value`. The comparison adds nothing.

A `boolean | undefined` is allowed by default, because there `=== true` also decides what happens with `undefined`. A `boolean | string` is never reported.

`--fix` replaces the comparison with the value or its negation.

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

## Configure

Off by default. This rule needs types, so turning it on makes `bun lint` type check your code first.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-unnecessary-boolean-literal-compare" = "error"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-unnecessary-boolean-literal-compare" = ["error", {
  allowComparingNullableBooleansToTrue = true,
  allowComparingNullableBooleansToFalse = true,
  allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing = false,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
function canEdit(isOwner: boolean, isLocked: boolean) {
  return isOwner === true && isLocked === false;
}
```

Not reported:

{/* good */}
```ts
function canEdit(isOwner: boolean, isLocked: boolean) {
  return isOwner && !isLocked;
}

function isPinned(pinned?: boolean, mode?: boolean | string) {
  return pinned === true || mode === true;
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowComparingNullableBooleansToTrue` | `true` | Allow `value === true` where `value` can also be `null` or `undefined`. |
| `allowComparingNullableBooleansToFalse` | `true` | Allow `value === false` where `value` can also be `null` or `undefined`. |
| `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing` | `false` | Without `strictNullChecks` in `tsconfig.json`, the rule can't tell what can be `null`, and it reports that once for each file. Set this to `true` to turn that report off. |

With `allowComparingNullableBooleansToTrue` off, write `if (isPinned)` instead:

{/* bad {"options": [{"allowComparingNullableBooleansToTrue": false}]} */}
```ts
function pin(isPinned?: boolean) {
  if (isPinned === true) {
    console.log("pinned");
  }
}
```

With `allowComparingNullableBooleansToFalse` off, write `!(isPinned ?? true)` instead, which says what `undefined` counts as:

{/* bad {"options": [{"allowComparingNullableBooleansToFalse": false}]} */}
```ts
function pin(isPinned?: boolean) {
  if (isPinned === false) {
    console.log("not pinned");
  }
}
```
