lib/rules/prefer-const.js
function checkGroup(nodes) {
            const nodesToReport = nodes.filter(Boolean);

            if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) {
                const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement"));
                const isVarDecParentNull = varDeclParent === null;

                if (!isVarDecParentNull && varDeclParent.declarations.length > 0) {
                    const firstDeclaration = varDeclParent.declarations[0];

                    if (firstDeclaration.init) {
                        const firstDecParent = firstDeclaration.init.parent;

                        /*
                         * First we check the declaration type and then depending on
                         * if the type is a "VariableDeclarator" or its an "ObjectPattern"
                         * we compare the name from the first identifier, if the names are different
                         * we assign the new name and reset the count of reportCount and nodeCount in
                         * order to check each block for the number of reported errors and base our fix
                         * based on comparing nodes.length and nodesToReport.length.
                         */

                        if (firstDecParent.type === "VariableDeclarator") {

                            if (firstDecParent.id.name !== name) {
                                name = firstDecParent.id.name;
                                reportCount = 0;
                            }

                            if (firstDecParent.id.type === "ObjectPattern") {
                                if (firstDecParent.init.name !== name) {
                                    name = firstDecParent.init.name;
                                    reportCount = 0;
                                }
                            }
                        }
                    }
                }

                let shouldFix = varDeclParent &&

                    // Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop)
                    (varDeclParent.parent.type === "ForInStatement" || varDeclParent.parent.type === "ForOfStatement" || varDeclParent.declarations[0].init) &&

                    /*
                     * If options.destructuring is "all", then this warning will not occur unless
                     * every assignment in the destructuring should be const. In that case, it's safe
                     * to apply the fix.
                     */
                    nodesToReport.length === nodes.length;

                if (!isVarDecParentNull && varDeclParent.declarations && varDeclParent.declarations.length !== 1) {

                    if (varDeclParent && varDeclParent.declarations && varDeclParent.declarations.length >= 1) {

                        /*
                         * Add nodesToReport.length to a count, then comparing the count to the length
                         * of the declarations in the current block.
                         */

                        reportCount += nodesToReport.length;

                        shouldFix = shouldFix && (reportCount === varDeclParent.declarations.length);
                    }
                }

                nodesToReport.forEach(node => {
                    context.report({
                        node,
                        messageId: "useConst",
                        data: node,
                        fix: shouldFix ? fixer => fixer.replaceText(sourceCode.getFirstToken(varDeclParent), "const") : null
                    });
                });
            }
        }
function checkGroup(nodes) {
            const nodesToReport = nodes.filter(Boolean);

            if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) {
                const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement"));
                const isVarDecParentNull = varDeclParent === null;

                if (!isVarDecParentNull && varDeclParent.declarations.length > 0) {
                    const firstDeclaration = varDeclParent.declarations[0];

                    if (firstDeclaration.init) {
                        const firstDecParent = firstDeclaration.init.parent;

                        /*
                         * First we check the declaration type and then depending on
                         * if the type is a "VariableDeclarator" or its an "ObjectPattern"
                         * we compare the name from the first identifier, if the names are different
                         * we assign the new name and reset the count of reportCount and nodeCount in
                         * order to check each block for the number of reported errors and base our fix
                         * based on comparing nodes.length and nodesToReport.length.
                         */

                        if (firstDecParent.type === "VariableDeclarator") {

                            if (firstDecParent.id.name !== name) {
                                name = firstDecParent.id.name;
                                reportCount = 0;
                            }

                            if (firstDecParent.id.type === "ObjectPattern") {
                                if (firstDecParent.init.name !== name) {
                                    name = firstDecParent.init.name;
                                    reportCount = 0;
                                }
                            }
                        }
                    }
                }

                let shouldFix = varDeclParent &&

                    // Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop)
                    (varDeclParent.parent.type === "ForInStatement" || varDeclParent.parent.type === "ForOfStatement" || varDeclParent.declarations[0].init) &&

                    /*
                     * If options.destructuring is "all", then this warning will not occur unless
                     * every assignment in the destructuring should be const. In that case, it's safe
                     * to apply the fix.
                     */
                    nodesToReport.length === nodes.length;

                if (!isVarDecParentNull && varDeclParent.declarations && varDeclParent.declarations.length !== 1) {

                    if (varDeclParent && varDeclParent.declarations && varDeclParent.declarations.length >= 1) {

                        /*
                         * Add nodesToReport.length to a count, then comparing the count to the length
                         * of the declarations in the current block.
                         */

                        reportCount += nodesToReport.length;

                        shouldFix = shouldFix && (reportCount === varDeclParent.declarations.length);
                    }
                }

                nodesToReport.forEach(node => {
                    context.report({
                        node,
                        messageId: "useConst",
                        data: node,
                        fix: shouldFix ? fixer => fixer.replaceText(sourceCode.getFirstToken(varDeclParent), "const") : null
                    });
                });
            }
        }
function checkGroup ( nodes ) { const nodesToReport = nodes . filter ( Boolean ) ; if ( nodes . length && ( shouldMatchAnyDestructuredVariable || nodesToReport . length === nodes . length ) ) { const varDeclParent = findUp ( nodes [ 0 ] , "VariableDeclaration" , parentNode => parentNode . type . endsWith ( "Statement" ) ) ; const isVarDecParentNull = varDeclParent === null ; if ( ! isVarDecParentNull && varDeclParent . declarations . length > 0 ) { const firstDeclaration = varDeclParent . declarations [ 0 ] ; if ( firstDeclaration . init ) { const firstDecParent = firstDeclaration . init . parent ; /*
                         * First we check the declaration type and then depending on
                         * if the type is a "VariableDeclarator" or its an "ObjectPattern"
                         * we compare the name from the first identifier, if the names are different
                         * we assign the new name and reset the count of reportCount and nodeCount in
                         * order to check each block for the number of reported errors and base our fix
                         * based on comparing nodes.length and nodesToReport.length.
                         */ if ( firstDecParent . type === "VariableDeclarator" ) { if ( firstDecParent . id . name !== name ) { name = firstDecParent . id . name ; reportCount = 0 ; } if ( firstDecParent . id . type === "ObjectPattern" ) { if ( firstDecParent . init . name !== name ) { name = firstDecParent . init . name ; reportCount = 0 ; } } } } } let shouldFix = varDeclParent && // Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop) ( varDeclParent . parent . type === "ForInStatement" || varDeclParent . parent . type === "ForOfStatement" || varDeclParent . declarations [ 0 ] . init ) && /*
                     * If options.destructuring is "all", then this warning will not occur unless
                     * every assignment in the destructuring should be const. In that case, it's safe
                     * to apply the fix.
                     */ nodesToReport . length === nodes . length ; if ( ! isVarDecParentNull && varDeclParent . declarations && varDeclParent . declarations . length !== 1 ) { if ( varDeclParent && varDeclParent . declarations && varDeclParent . declarations . length >= 1 ) { /*
                         * Add nodesToReport.length to a count, then comparing the count to the length
                         * of the declarations in the current block.
                         */ reportCount += nodesToReport . length ; shouldFix = shouldFix && ( reportCount === varDeclParent . declarations . length ) ; } } nodesToReport . forEach ( node => { context . report ( { node , messageId : "useConst" , data : node , fix : shouldFix ? fixer => fixer . replaceText ( sourceCode . getFirstToken ( varDeclParent ) , "const" ) : null } ) ; } ) ; } }
Reports given identifier nodes if all of the nodes should be declared
as const.

The argument 'nodes' is an array of Identifier nodes.
This node is the result of 'getIdentifierIfShouldBeConst()', so it's
nullable. In simple declaration or assignment cases, the length of
the array is 1. In destructuring cases, the length of the array can
be 2 or more.

@param {(eslint-scope.Reference|null)[]} nodes -
References which are grouped by destructuring to report.
@returns {void}
Reports given identifier nodes if all of the nodes should be declared as const .