Repository: eslint/eslint
File: tests/lib/rules/prefer-named-capture-group.js (JavaScript)

Code before:
                        messageId: "addNonCapture",
                        output: "RegExp('(?:[0-9]{4})')"
                    }
                ]
            }]
        },
        {
            code: "new RegExp(`a(bc)d`)",
            errors: [{
                messageId: "required",
                type: "NewExpression",
                data: { group: "(bc)" },
                suggestions: [
                    {
                        messageId: "addGroupName",
                        output: "new RegExp(`a(?<temp1>bc)d`)"
                    },
                    {
                        messageId: "addNonCapture",
                        output: "new RegExp(`a(?:bc)d`)"
                    }
                ]
            }]
        },
        {
            code: "new RegExp('\u1234\u5678(?:a)(b)');",
            errors: [{
                messageId: "required",
                type: "NewExpression",
                data: { group: "(b)" },
                suggestions: [
                    {
                        messageId: "addGroupName",
                        output: "new RegExp('\u1234\u5678(?:a)(?<temp1>b)');"
                    },
                    {
                        messageId: "addNonCapture",
                        output: "new RegExp('\u1234\u5678(?:a)(?:b)');"
                    }
                ]
            }]
        },
        {
            code: "/([0-9]{4})-(\\w{5})/",
            errors: [
                {
                    messageId: "required",
                    type: "Literal",
                    data: { group: "([0-9]{4})" },
                    line: 1,
                    column: 1,

Review comment (security):
`\u1234` and `\u5678` are evaluated for the `code` string, so this tests the following source code:

```js
new RegExp('ሴ噸(?:a)(b)');
```

If we want to test `new RegExp("\u1234\u5678(?:a)(b)");` source code, we should escape `\`:

```suggestion
            code: "new RegExp('\\u1234\\u5678(?:a)(b)');",
```




Code after:
                        messageId: "addNonCapture",
                        output: "RegExp('(?:[0-9]{4})')"
                    }
                ]
            }]
        },
        {
            code: "new RegExp(`a(bc)d`)",
            errors: [{
                messageId: "required",
                type: "NewExpression",
                data: { group: "(bc)" },
                suggestions: [
                    {
                        messageId: "addGroupName",
                        output: "new RegExp(`a(?<temp1>bc)d`)"
                    },
                    {
                        messageId: "addNonCapture",
                        output: "new RegExp(`a(?:bc)d`)"
                    }
                ]
            }]
        },
        {
            code: "new RegExp('\u1234\u5678(?:a)(b)');",
            errors: [{
                messageId: "required",
                type: "NewExpression",
                data: { group: "(b)" },
                suggestions: [
                    {
                        messageId: "addGroupName",
                        output: "new RegExp('\u1234\u5678(?:a)(?<temp1>b)');"
                    },
                    {
                        messageId: "addNonCapture",
                        output: "new RegExp('\u1234\u5678(?:a)(?:b)');"
                    }
                ]
            }]
        },
        {
            code: "new RegExp('\\u1234\\u5678(?:a)(b)');",
            errors: [{
                messageId: "required",
                type: "NewExpression",
                data: { group: "(b)" },
                suggestions: null
            }]
        },