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

Code before:
            }]
        },
        {
            code: "new RegExp('.', 'aaz');",
            options: [{ allowConstructorFlags: ["a", "z"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'a'" },
                type: "NewExpression"
            }]
        },
        {
            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 'ga'" },
                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" },

Review comment (refactor):
I'm not sure this error message is clear enough. `"g"` is a valid flag and `"a"` was allowed in the options, so it's not obvious why `'ga'` would be invalid. If `a` is replaced with a valid flag like `u`, the error message includes the flag duplication but also the valid flag `"g"`, which is still inconsistent:

```js
new RegExp('.', 'ugu');
// Invalid flags supplied to RegExp constructor 'ugu'
```

Maybe there should be a new message for duplicated flags?

Code after:
            }]
        },
        {
            code: "new RegExp('.', 'aA');",
            options: [{ allowConstructorFlags: ["a"] }],
            errors: [{
                messageId: "regexMessage",
                data: { message: "Invalid flags supplied to RegExp constructor 'A'" },
                type: "NewExpression"
            }]
        },
        {
            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",