]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-underscore-dangle.js
import 8.41.0 source
[pve-eslint.git] / eslint / tests / lib / rules / no-underscore-dangle.js
index f3e11cc3e76b05bb2afc27dab831a24560948908..cec2c2ac722913c6f0ee58661fc6de4a5b835dcb 100644 (file)
@@ -70,6 +70,17 @@ ruleTester.run("no-underscore-dangle", rule, {
         { code: "function foo( { _bar }) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } },
         { code: "function foo( { _bar = 0 } = {}) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } },
         { code: "function foo(...[_bar]) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 2016 } },
+        { code: "const [_foo] = arr", parserOptions: { ecmaVersion: 6 } },
+        { code: "const [_foo] = arr", options: [{}], parserOptions: { ecmaVersion: 6 } },
+        { code: "const [_foo] = arr", options: [{ allowInArrayDestructuring: true }], parserOptions: { ecmaVersion: 6 } },
+        { code: "const [foo, ...rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "const [foo, _bar] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "const { _foo } = obj", parserOptions: { ecmaVersion: 6 } },
+        { code: "const { _foo } = obj", options: [{}], parserOptions: { ecmaVersion: 6 } },
+        { code: "const { _foo } = obj", options: [{ allowInObjectDestructuring: true }], parserOptions: { ecmaVersion: 6 } },
+        { code: "const { foo, bar: _bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "const { foo, _bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "const { foo, _bar: bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false }], parserOptions: { ecmaVersion: 2022 } },
         { code: "class foo { _field; }", parserOptions: { ecmaVersion: 2022 } },
         { code: "class foo { _field; }", options: [{ enforceInClassFields: false }], parserOptions: { ecmaVersion: 2022 } },
         { code: "class foo { #_field; }", parserOptions: { ecmaVersion: 2022 } },
@@ -103,6 +114,77 @@ ruleTester.run("no-underscore-dangle", rule, {
         { code: "const foo = { onClick(..._bar) { } }", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] },
         { code: "const foo = (..._bar) => {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] },
         {
+            code: "const [foo, _bar] = [1, 2]",
+            options: [{ allowInArrayDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }]
+        }, {
+            code: "const [_foo = 1] = arr",
+            options: [{ allowInArrayDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }]
+        }, {
+            code: "const [foo, ..._rest] = [1, 2, 3]",
+            options: [{ allowInArrayDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }]
+        }, {
+            code: "const [foo, [bar_, baz]] = [1, [2, 3]]",
+            options: [{ allowInArrayDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }]
+        }, {
+            code: "const { _foo, bar } = { _foo: 1, bar: 2 }",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }]
+        }, {
+            code: "const { _foo = 1 } = obj",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }]
+        }, {
+            code: "const { bar: _foo = 1 } = obj",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }]
+        }, {
+            code: "const { foo: _foo, bar } = { foo: 1, bar: 2 }",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }]
+        }, {
+            code: "const { foo, ..._rest} = { foo: 1, bar: 2, baz: 3 }",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }]
+        }, {
+            code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }",
+            options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [
+                { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } },
+                { messageId: "unexpectedUnderscore", data: { identifier: "_a" } }
+            ]
+        }, {
+            code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }",
+            options: [{ allowInArrayDestructuring: true, allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_a" } }]
+        }, {
+            code: "const [{ foo: [_bar, _, { bar: _baz }] }] = [{ foo: [1, 2, { bar: 'a' }] }]",
+            options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [
+                { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } },
+                { messageId: "unexpectedUnderscore", data: { identifier: "_baz" } }
+            ]
+        }, {
+            code: "const { foo, bar: { baz, _qux } } = { foo: 1, bar: { baz: 3, _qux: 4 } }",
+            options: [{ allowInObjectDestructuring: false }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }]
+        }, {
             code: "class foo { #_bar() {} }",
             options: [{ enforceInMethodNames: true }],
             parserOptions: { ecmaVersion: 2022 },