]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/prefer-destructuring.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / rules / prefer-destructuring.js
index 8f111a1d8c2f0f7d4fe1e2292e7c3ddaf86b4118..7f808a642180e514329e08e85d6be090743cbf5f 100644 (file)
@@ -16,7 +16,7 @@ const rule = require("../../../lib/rules/prefer-destructuring"),
 // Tests
 //------------------------------------------------------------------------------
 
-const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } });
+const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } });
 
 ruleTester.run("prefer-destructuring", rule, {
     valid: [
@@ -157,7 +157,40 @@ ruleTester.run("prefer-destructuring", rule, {
 
         // Optional chaining
         "var foo = array?.[0];", // because the fixed code can throw TypeError.
-        "var foo = object?.foo;"
+        "var foo = object?.foo;",
+
+        // Private identifiers
+        "class C { #x; foo() { const x = this.#x; } }",
+        "class C { #x; foo() { x = this.#x; } }",
+        "class C { #x; foo(a) { x = a.#x; } }",
+        {
+            code: "class C { #x; foo() { const x = this.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo() { const y = this.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo() { x = this.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo() { y = this.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo(a) { x = a.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo(a) { y = a.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        },
+        {
+            code: "class C { #x; foo() { x = this.a.#x; } }",
+            options: [{ array: true, object: true }, { enforceForRenamedProperties: true }]
+        }
     ],
 
     invalid: [