Repository: eslint/eslint
File: tests/lib/rules/no-extra-parens.js (JavaScript)

Code before:
        invalid("(a) = class Bar {};", "a = class Bar {};", "Identifier"),
        invalid("(a.b) = function () {};", "a.b = function () {};", "MemberExpression"),
        {
            code: "(newClass) = [(one)] = class { static * [Symbol.iterator]() { yield 1; } };",
            output: "newClass = [one] = class { static * [Symbol.iterator]() { yield 1; } };",
            errors: [
                { messageId: "unexpected", type: "Identifier" },
                { messageId: "unexpected", type: "Identifier" }
            ]
        },
        invalid("((a)) = () => {};", "(a) = () => {};", "Identifier"),
        invalid("(a) = (function () {})();", "a = (function () {})();", "Identifier"),
        ...["**=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|="].map(
            operator => invalid(
                `(a) ${operator} function () {};`,
                `a ${operator} function () {};`,
                "Identifier"
            )
        ),

        // Potential directives (no autofix)
        invalid("('use strict');", null),
        invalid("function f() { ('abc'); }", null),
        invalid("(function () { ('abc'); })();", null),
        invalid("_ = () => { ('abc'); };", null),
        invalid("'use strict';(\"foobar\");", null),

        // Directive lookalikes
        invalid("(12345);", "12345;"),
        invalid("(('foobar'));", "('foobar');"),
        invalid("(`foobar`);", "`foobar`;"),
        invalid("void ('foobar');", "void 'foobar';"),
        invalid("_ = () => ('abc');", "_ = () => 'abc';"),
        invalid("if (foo) ('bar');", "if (foo) 'bar';"),
        invalid("const foo = () => ('bar');", "const foo = () => 'bar';")
    ]
});


Review comment (suggestion):
I think these all would really become directives. It would be good to also add a test where the expression statement wouldn't end up in the directive prologue so that we confirm that the no-autofix behavior in such case is intentional.

For example: `invalid("foo(); ('bar');", null),`

Code after:
        invalid("(a) = class Bar {};", "a = class Bar {};", "Identifier"),
        invalid("(a.b) = function () {};", "a.b = function () {};", "MemberExpression"),
        {
            code: "(newClass) = [(one)] = class { static * [Symbol.iterator]() { yield 1; } };",
            output: "newClass = [one] = class { static * [Symbol.iterator]() { yield 1; } };",
            errors: [
                { messageId: "unexpected", type: "Identifier" },
                { messageId: "unexpected", type: "Identifier" }
            ]
        },
        invalid("((a)) = () => {};", "(a) = () => {};", "Identifier"),
        invalid("(a) = (function () {})();", "a = (function () {})();", "Identifier"),
        ...["**=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|="].map(
            operator => invalid(
                `(a) ${operator} function () {};`,
                `a ${operator} function () {};`,
                "Identifier"
            )
        ),

        // Potential directives (no autofix)
        invalid("('use strict');", null),
        invalid("function f() { ('abc'); }", null),
        invalid("(function () { ('abc'); })();", null),
        invalid("_ = () => { ('abc'); };", null),
        invalid("'use strict';(\"foobar\");", null),
        invalid("foo(); ('bar');", null),
        invalid("foo = { bar() { ; (\"baz\"); } };", null),

        // Directive lookalikes
        invalid("(12345);", "12345;"),
        invalid("(('foobar'));", "('foobar');"),
        invalid("(`foobar`);", "`foobar`;"),
        invalid("void ('foobar');", "void 'foobar';"),
        invalid("_ = () => ('abc');", "_ = () => 'abc';"),
        invalid("if (foo) ('bar');", "if (foo) 'bar';"),
        invalid("const foo = () => ('bar');", "const foo = () => 'bar';")
    ]
});