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

Code before:
        docs: {
            description: "Enforce using named capture group in regular expression",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/prefer-named-capture-group"
        },

        hasSuggestions: true,

        schema: [],

        messages: {
            addGroupName: "Add name to capture group.",
            addNonCapture: "Convert group to non-capturing.",
            required: "Capture group '{{group}}' should be converted to a named or non-capturing group."
        }
    },

    create(context) {
        const sourceCode = context.sourceCode;

        /**
         * Function to check regular expression.
         * @param {string} pattern The regular expression pattern to be checked.
         * @param {ASTNode} node AST node which contains the regular expression or a call/new expression.
         * @param {ASTNode} regexNode AST node which contains the regular expression.
         * @param {string} flags The regular expression flags to be checked.
         * @returns {void}
         */
        function checkRegex(pattern, node, regexNode, flags) {
            let ast;

            try {
                ast = parser.parsePattern(pattern, 0, pattern.length, {
                    unicode: Boolean(flags && flags.includes("u")),
                    unicodeSets: Boolean(flags && flags.includes("v"))
                });
            } catch {

                // ignore regex syntax errors
                return;
            }

            regexpp.visitRegExpAST(ast, {
                onCapturingGroupEnter(group) {
                    if (!group.name) {
                        const rawText = sourceCode.getText(regexNode);
                        const suggest = suggestIfPossible(group.start, pattern, rawText, regexNode);

                        context.report({
                            node,
                            messageId: "required",

Review comment (suggestion):
```suggestion
         * @param {string|null} flags The regular expression flags to be checked.
```

Code after:
        docs: {
            description: "Enforce using named capture group in regular expression",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/prefer-named-capture-group"
        },

        hasSuggestions: true,

        schema: [],

        messages: {
            addGroupName: "Add name to capture group.",
            addNonCapture: "Convert group to non-capturing.",
            required: "Capture group '{{group}}' should be converted to a named or non-capturing group."
        }
    },

    create(context) {
        const sourceCode = context.sourceCode;

        /**
         * Function to check regular expression.
         * @param {string} pattern The regular expression pattern to be checked.
         * @param {ASTNode} node AST node which contains the regular expression or a call/new expression.
         * @param {ASTNode} regexNode AST node which contains the regular expression.
         * @param {string|null} flags The regular expression flags to be checked.
         * @returns {void}
         */
        function checkRegex(pattern, node, regexNode, flags) {
            let ast;

            try {
                ast = parser.parsePattern(pattern, 0, pattern.length, {
                    unicode: Boolean(flags && flags.includes("u")),
                    unicodeSets: Boolean(flags && flags.includes("v"))
                });
            } catch {

                // ignore regex syntax errors
                return;
            }

            regexpp.visitRegExpAST(ast, {
                onCapturingGroupEnter(group) {
                    if (!group.name) {
                        const rawText = sourceCode.getText(regexNode);
                        const suggest = suggestIfPossible(group.start, pattern, rawText, regexNode);

                        context.report({
                            node,
                            messageId: "required",