Repository: eslint/eslint
File: tests/lib/rules/no-underscore-dangle.js (JavaScript)

Code before:
        }, {
            code: "class foo { #_bar() {} }",
            options: [{ enforceInMethodNames: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }]
        }, {
            code: "class foo { #bar_() {} }",
            options: [{ enforceInMethodNames: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }]
        },
        {
            code: "class foo { _field; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }]
        },
        {
            code: "class foo { #_field; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }]
        },
        {
            code: "class foo { field_; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }]
        },
        {
            code: "class foo { #field_; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }]
        }
    ]
});


Review comment (suggestion):
To protect us from accidentally breaking these in the future, will you add a test or tests to cover a) reporting multiple destructured identifiers and b) nesting objects within arrays or vice versa? Something like `const {arr: [_first, {_second}]} = obj;`, for example.

Code after:
            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 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }]
        }, {
            code: "class foo { #bar_() {} }",
            options: [{ enforceInMethodNames: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }]
        },
        {
            code: "class foo { _field; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }]
        },
        {
            code: "class foo { #_field; }",
            options: [{ enforceInClassFields: true }],
            parserOptions: { ecmaVersion: 2022 },
            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }]
        },
        {
            code: "class foo { field_; }",
            options: [{ enforceInClassFields: true }],