Repository: eslint/eslint
File: tests/lib/rules/require-unicode-regexp.js (JavaScript)

Code before:
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({
    parserOptions: { ecmaVersion: 2015 }
});

ruleTester.run("require-unicode-regexp", rule, {
    valid: [
        "/foo/u",
        "/foo/gimuy",
        "RegExp('', 'u')",
        "RegExp('', `u`)",
        "new RegExp('', 'u')",
        "RegExp('', 'gimuy')",
        "RegExp('', `gimuy`)",
        "new RegExp('', 'gimuy')",
        "const flags = 'u'; new RegExp('', flags)",
        "const flags = 'g'; new RegExp('', flags + 'u')",
        "const flags = 'gimu'; new RegExp('foo', flags[3])",
        "new RegExp('', flags)",
        "function f(flags) { return new RegExp('', flags) }",
        "function f(RegExp) { return new RegExp('foo') }",
        "function f(patternAndFlags) { return new RegExp(...patternAndFlags) }",
        { code: "new globalThis.RegExp('foo')", env: { es6: true } },
        { code: "new globalThis.RegExp('foo')", env: { es2017: true } },
        { code: "new globalThis.RegExp('foo', 'u')", env: { es2020: true } },
        { code: "globalThis.RegExp('foo', 'u')", env: { es2020: true } },
        { code: "const flags = 'u'; new globalThis.RegExp('', flags)", env: { es2020: true } },
        { code: "const flags = 'g'; new globalThis.RegExp('', flags + 'u')", env: { es2020: true } },
        { code: "const flags = 'gimu'; new globalThis.RegExp('foo', flags[3])", env: { es2020: true } },
        { code: "class C { #RegExp; foo() { new globalThis.#RegExp('foo') } }", parserOptions: { ecmaVersion: 2022 }, env: { es2020: true } }
    ],
    invalid: [
        {
            code: "/\\a/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: null
            }]
        },
        {
            code: "/foo/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: [
                    {
                        messageId: "addUFlag",
                        output: "/foo/u"
                    }

Review comment (suggestion):
good to have a test like `RegExp(...patternAndFlags)` (no `new`, as you described in the PR desc).

otherwise LGTM! 👍 

Code after:
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({
    parserOptions: { ecmaVersion: 2015 }
});

ruleTester.run("require-unicode-regexp", rule, {
    valid: [
        "/foo/u",
        "/foo/gimuy",
        "RegExp('', 'u')",
        "RegExp('', `u`)",
        "new RegExp('', 'u')",
        "RegExp('', 'gimuy')",
        "RegExp('', `gimuy`)",
        "RegExp(...patternAndFlags)",
        "new RegExp('', 'gimuy')",
        "const flags = 'u'; new RegExp('', flags)",
        "const flags = 'g'; new RegExp('', flags + 'u')",
        "const flags = 'gimu'; new RegExp('foo', flags[3])",
        "new RegExp('', flags)",
        "function f(flags) { return new RegExp('', flags) }",
        "function f(RegExp) { return new RegExp('foo') }",
        "function f(patternAndFlags) { return new RegExp(...patternAndFlags) }",
        { code: "new globalThis.RegExp('foo')", env: { es6: true } },
        { code: "new globalThis.RegExp('foo')", env: { es2017: true } },
        { code: "new globalThis.RegExp('foo', 'u')", env: { es2020: true } },
        { code: "globalThis.RegExp('foo', 'u')", env: { es2020: true } },
        { code: "const flags = 'u'; new globalThis.RegExp('', flags)", env: { es2020: true } },
        { code: "const flags = 'g'; new globalThis.RegExp('', flags + 'u')", env: { es2020: true } },
        { code: "const flags = 'gimu'; new globalThis.RegExp('foo', flags[3])", env: { es2020: true } },
        { code: "class C { #RegExp; foo() { new globalThis.#RegExp('foo') } }", parserOptions: { ecmaVersion: 2022 }, env: { es2020: true } }
    ],
    invalid: [
        {
            code: "/\\a/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: null
            }]
        },
        {
            code: "/foo/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: [
                    {
                        messageId: "addUFlag",
                        output: "/foo/u"