From 6e1241bba5957b9ba9efc1716723f52d63fbb305 Mon Sep 17 00:00:00 2001 From: Heitor Lisboa <89428328+heitorlisboa@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:24:31 -0300 Subject: [PATCH] docs: fix no-unnecessary-boolean-literal-compare example (#8981) * docs: fix no-unnecessary-boolean-literal-compare example * docs: use simpler expressions on no-unnecessary-boolean-literal-compare examples --- ...no-unnecessary-boolean-literal-compare.mdx | 24 +++++++++---------- ...o-unnecessary-boolean-literal-compare.shot | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.mdx b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.mdx index d0ca9544a58..51c13eecb15 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.mdx +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.mdx @@ -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) { } ``` @@ -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 diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-unnecessary-boolean-literal-compare.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-unnecessary-boolean-literal-compare.shot index 3397a172781..878e1149f7d 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-unnecessary-boolean-literal-compare.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-unnecessary-boolean-literal-compare.shot @@ -78,11 +78,11 @@ exports[`Validating rule docs no-unnecessary-boolean-literal-compare.mdx code ex Options: { "allowComparingNullableBooleansToFalse": false } declare const someUndefinedCondition: boolean | undefined; -if (someUndefinedCondition ?? true) { +if (!(someUndefinedCondition ?? true)) { } declare const someNullCondition: boolean | null; -if (!(someNullCondition ?? true)) { +if (someNullCondition ?? true) { } " `;