]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-unused-expressions.js
import eslint 7.28.0
[pve-eslint.git] / eslint / tests / lib / rules / no-unused-expressions.js
index 8ef2028c66207a6a90e8edb0264b8b30288f80a7..6f49a0a24fba523a69185ea53c30da5c86ed4cdf 100644 (file)
@@ -74,6 +74,38 @@ ruleTester.run("no-unused-expressions", rule, {
         {
             code: "import(\"foo\")",
             parserOptions: { ecmaVersion: 11 }
+        },
+        {
+            code: "func?.(\"foo\")",
+            parserOptions: { ecmaVersion: 11 }
+        },
+        {
+            code: "obj?.foo(\"bar\")",
+            parserOptions: { ecmaVersion: 11 }
+        },
+
+        // JSX
+        {
+            code: "<div />",
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
+        {
+            code: "<></>",
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
+        {
+            code: "var partial = <div />",
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
+        {
+            code: "var partial = <div />",
+            options: [{ enforceForJSX: true }],
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
+        {
+            code: "var partial = <></>",
+            options: [{ enforceForJSX: true }],
+            parserOptions: { ecmaFeatures: { jsx: true } }
         }
     ],
     invalid: [
@@ -127,6 +159,37 @@ ruleTester.run("no-unused-expressions", rule, {
             options: [{ allowTaggedTemplates: false }],
             parserOptions: { ecmaVersion: 6 },
             errors: [{ messageId: "unusedExpression" }]
+        },
+
+        // Optional chaining
+        {
+            code: "obj?.foo",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }]
+        },
+        {
+            code: "obj?.foo.bar",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }]
+        },
+        {
+            code: "obj?.foo().bar",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }]
+        },
+
+        // JSX
+        {
+            code: "<div />",
+            options: [{ enforceForJSX: true }],
+            parserOptions: { ecmaFeatures: { jsx: true } },
+            errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }]
+        },
+        {
+            code: "<></>",
+            options: [{ enforceForJSX: true }],
+            parserOptions: { ecmaFeatures: { jsx: true } },
+            errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }]
         }
     ]
 });