Skip to content

Commit

Permalink
docs: fix no-unnecessary-boolean-literal-compare example (#8981)
Browse files Browse the repository at this point in the history
* docs: fix no-unnecessary-boolean-literal-compare example

* docs: use simpler expressions on no-unnecessary-boolean-literal-compare examples
  • Loading branch information
heitorlisboa committed Apr 29, 2024
1 parent ee677f6 commit 6e1241b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ if (someNullCondition !== false) {

```ts option='{ "allowComparingNullableBooleansToFalse": false }'
declare const someUndefinedCondition: boolean | undefined;
if (someUndefinedCondition ?? true) {
if (!(someUndefinedCondition ?? true)) {
}

declare const someNullCondition: boolean | null;
if (!(someNullCondition ?? true)) {
if (someNullCondition ?? true) {
}
```

Expand All @@ -127,16 +127,16 @@ if (!(someNullCondition ?? true)) {

## Fixer

| Comparison | Fixer Output | Notes |
| :-------------------------------: | ------------------------------- | ----------------------------------------------------------------------------------- |
| `booleanVar === true` | `booleanVar` | |
| `booleanVar !== true` | `!booleanVar` | |
| `booleanVar === false` | `!booleanVar` | |
| `booleanVar !== false` | `booleanVar` | |
| `nullableBooleanVar === true` | `nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
| `nullableBooleanVar !== true` | `!nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
| `!(nullableBooleanVar === false)` | `nullableBooleanVar ?? true` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
| `!(nullableBooleanVar !== false)` | `!(nullableBooleanVar ?? true)` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
| Comparison | Fixer Output | Notes |
| :----------------------------: | ------------------------------- | ----------------------------------------------------------------------------------- |
| `booleanVar === true` | `booleanVar` | |
| `booleanVar !== true` | `!booleanVar` | |
| `booleanVar === false` | `!booleanVar` | |
| `booleanVar !== false` | `booleanVar` | |
| `nullableBooleanVar === true` | `nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
| `nullableBooleanVar !== true` | `!nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
| `nullableBooleanVar === false` | `!(nullableBooleanVar ?? true)` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
| `nullableBooleanVar !== false` | `nullableBooleanVar ?? true` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |

## When Not To Use It

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e1241b

Please sign in to comment.