From 237b055fad3c9b7fe6d719d939675d4090a14103 Mon Sep 17 00:00:00 2001 From: Eva1ent <rel1cx@proton.me> Date: Mon, 18 Nov 2024 16:18:02 +0800 Subject: [PATCH] fix(plugins/x): 'no-leaked-conditional-rendering' report empty string, closes #853 (#857) --- package.json | 2 +- .../no-leaked-conditional-rendering.spec.ts | 25 ++++++++++++++++++- .../rules/no-leaked-conditional-rendering.ts | 1 - pnpm-lock.yaml | 16 ++++++------ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 5b35b5c36..e6d63a321 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "eslint-import-resolver-oxc": "^0.4.0", "eslint-plugin-better-mutation": "^1.5.0", "eslint-plugin-eslint-comments": "^3.2.0", - "eslint-plugin-eslint-plugin": "^6.3.1", + "eslint-plugin-eslint-plugin": "^6.3.2", "eslint-plugin-import-x": "^4.4.2", "eslint-plugin-jsdoc": "^50.5.0", "eslint-plugin-perfectionist": "^3.9.1", diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.spec.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.spec.ts index 79db316e3..77c953da5 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.spec.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.spec.ts @@ -3,6 +3,29 @@ import rule, { RULE_NAME } from "./no-leaked-conditional-rendering"; ruleTesterWithTypes.run(RULE_NAME, rule, { invalid: [ + { + code: /* tsx */ ` + /// <reference types="react" /> + /// <reference types="react-dom" /> + + const a = <>{"" && <Something />}</>; + `, + errors: [ + { messageId: "noLeakedConditionalRendering" }, + ], + }, + { + code: /* tsx */ ` + /// <reference types="react" /> + /// <reference types="react-dom" /> + + const someString = ""; + const a = <>{someString && <Something />}</>; + `, + errors: [ + { messageId: "noLeakedConditionalRendering" }, + ], + }, { code: /* tsx */ ` /// <reference types="react" /> @@ -400,7 +423,7 @@ ruleTesterWithTypes.run(RULE_NAME, rule, { const a = <> {0 ? <Foo /> : null} - {'' && <Foo />} + {'0' && <Foo />} {NaN ? <Foo /> : null} </> `, diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts index 05c6b4396..ebf352c63 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts @@ -55,7 +55,6 @@ const allowedVariants = [ "nullish", "object", "string", - "falsy string", "falsy boolean", "truthy bigint", "truthy boolean", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f982178dd..e0bb85b2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,16 +5,16 @@ settings: excludeLinksFromLockfile: false overrides: - '@typescript-eslint/eslint-plugin': canary array-flatten: npm:@nolyfill/array-flatten@^1.0.42 is-core-module: npm:@nolyfill/is-core-module@^1.0.39 isarray: npm:@nolyfill/isarray@^1.0.29 - nextra: 3.1.0 - nextra-theme-docs: 3.1.0 safe-buffer: npm:@nolyfill/safe-buffer@^1.0.41 safer-buffer: npm:@nolyfill/safer-buffer@^1.0.41 side-channel: npm:@nolyfill/side-channel@^1.0.29 typedarray: npm:@nolyfill/typedarray@^1.0.29 + '@typescript-eslint/eslint-plugin': canary + nextra: 3.1.0 + nextra-theme-docs: 3.1.0 typescript: ^5.6.3 valibot: 0.42.1 @@ -116,8 +116,8 @@ importers: specifier: ^3.2.0 version: 3.2.0(eslint@9.15.0(jiti@2.3.3)) eslint-plugin-eslint-plugin: - specifier: ^6.3.1 - version: 6.3.1(eslint@9.15.0(jiti@2.3.3)) + specifier: ^6.3.2 + version: 6.3.2(eslint@9.15.0(jiti@2.3.3)) eslint-plugin-import-x: specifier: ^4.4.2 version: 4.4.2(eslint@9.15.0(jiti@2.3.3))(typescript@5.6.3) @@ -5047,8 +5047,8 @@ packages: peerDependencies: eslint: '>=4.19.1' - eslint-plugin-eslint-plugin@6.3.1: - resolution: {integrity: sha512-5OUvS+kzpfbX3Pyt7ULYLJBGdjM/tGPdjePGFE50Lqdqcn/dB0f9ifbRCrCGWBt10Ljk7O6ajj3BPOZ8vmD50g==} + eslint-plugin-eslint-plugin@6.3.2: + resolution: {integrity: sha512-s1uCANS+Keha58j25OvirQZsxlu3yrmWzcGuotOjUmqIeEFrDDar0cobAuYjLRLzwfjMKICKoPTCbK1pDleqiw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: '>=8.23.0' @@ -12756,7 +12756,7 @@ snapshots: eslint: 9.15.0(jiti@2.3.3) ignore: 5.3.2 - eslint-plugin-eslint-plugin@6.3.1(eslint@9.15.0(jiti@2.3.3)): + eslint-plugin-eslint-plugin@6.3.2(eslint@9.15.0(jiti@2.3.3)): dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.15.0(jiti@2.3.3)) eslint: 9.15.0(jiti@2.3.3)