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

Code before:
        "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 } },

        // for v flag
        { code: "/foo/v", parserOptions: { ecmaVersion: 2024 } },
        { code: "/foo/gimuy", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', `v`)", parserOptions: { ecmaVersion: 2024 } },
        { code: "new RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', `gimvy`)", parserOptions: { ecmaVersion: 2024 } },
        { code: "new RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'v'; new RegExp('', flags)", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'g'; new RegExp('', flags + 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'gimv'; new RegExp('foo', flags[4])", parserOptions: { ecmaVersion: 2024 } }
    ],
    invalid: [
        {
            code: "/\\a/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: null
            }]
        },
        {
            code: "/foo/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: [
                    {
                        messageId: "addUFlag",
                        output: "/foo/u"
                    }
                ]
            }]
        },
        {
            code: "/foo/gimy",
            errors: [{
                messageId: "requireUFlag",

Review comment (suggestion):
```suggestion
        { code: "const flags = 'gimv'; new RegExp('foo', flags[3])", parserOptions: { ecmaVersion: 2024 } }
```

Did you mean `flags[3]` (`'v'`)? With `flags[4]`, flags are treated as unknown so the test passes regardless of the `v` flag.

Code after:
        "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 } },

        // for v flag
        { code: "/foo/v", parserOptions: { ecmaVersion: 2024 } },
        { code: "/foo/gimvy", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', `v`)", parserOptions: { ecmaVersion: 2024 } },
        { code: "new RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } },
        { code: "RegExp('', `gimvy`)", parserOptions: { ecmaVersion: 2024 } },
        { code: "new RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'v'; new RegExp('', flags)", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'g'; new RegExp('', flags + 'v')", parserOptions: { ecmaVersion: 2024 } },
        { code: "const flags = 'gimv'; new RegExp('foo', flags[3])", parserOptions: { ecmaVersion: 2024 } }
    ],
    invalid: [
        {
            code: "/\\a/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: null
            }]
        },
        {
            code: "/foo/",
            errors: [{
                messageId: "requireUFlag",
                suggestions: [
                    {
                        messageId: "addUFlag",
                        output: "/foo/u"
                    }
                ]
            }]
        },
        {
            code: "/foo/gimy",
            errors: [{
                messageId: "requireUFlag",