Repository: eslint/eslint
File: tests/lib/rules/no-invalid-regexp.js (JavaScript)

Code before:
            code: "new RegExp('.', 'azz');",
            options: [{ allowConstructorFlags: ["a", "z"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'z'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp('.', 'aga');",
            options: [{ allowConstructorFlags: ["a"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'a'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp('.', 'uu');",
            options: [{ allowConstructorFlags: ["u"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'u'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp(')');",
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid regular expression: /)/: Unmatched ')'" },
                type: "NewExpression"
            }]
        },
        {
            code: String.raw`new RegExp('\\a', 'u');`,
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid regular expression: /\\a/u: Invalid escape" },
                type: "NewExpression"
            }]
        },
        {
            code: String.raw`new RegExp('\\a', 'u');`,
            options: [{ allowConstructorFlags: ["u"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid regular expression: /\\a/u: Invalid escape" },
                type: "NewExpression"
            }]
        },

Review comment (refactor):
The current error message for this invalid case is better, because it shows the duplication:

> Invalid flags supplied to RegExp constructor 'uu'.

[**Playground link**](https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgbm8taW52YWxpZC1yZWdleHA6IFwiZXJyb3JcIiovXG5cbm5ldyBSZWdFeHAoJy4nLCAndXUnKTsiLCJvcHRpb25zIjp7InJ1bGVzIjp7fSwibGFuZ3VhZ2VPcHRpb25zIjp7InNvdXJjZVR5cGUiOiJtb2R1bGUiLCJwYXJzZXJPcHRpb25zIjp7ImVjbWFGZWF0dXJlcyI6e319fX19)

Can we keep the duplicated flags in the error message until we have a more specific message?

Code after:
            code: "new RegExp('.', 'aaz');",
            options: [{ allowConstructorFlags: ["a", "z"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'aa'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp('.', 'azz');",
            options: [{ allowConstructorFlags: ["a", "z"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'zz'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp('.', 'aga');",
            options: [{ allowConstructorFlags: ["a"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'aa'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp('.', 'uu');",
            options: [{ allowConstructorFlags: ["u"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'uu'" },
                type: "NewExpression"
            }]
        },
        {
            code: "new RegExp(')');",
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid regular expression: /)/: Unmatched ')'" },
                type: "NewExpression"
            }]
        },
        {
            code: String.raw`new RegExp('\\a', 'u');`,
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid regular expression: /\\a/u: Invalid escape" },
                type: "NewExpression"
            }]
        },