lib/rules/one-var.js
function splitDeclarations(declaration) {
            return fixer => declaration.declarations.map(declarator => {
                const tokenAfterDeclarator = sourceCode.getTokenAfter(declarator);

                if (tokenAfterDeclarator === null) {
                    return null;
                }

                const afterComma = sourceCode.getTokenAfter(tokenAfterDeclarator, { includeComments: true });

                if (tokenAfterDeclarator.value !== ",") {
                    return null;
                }

                /*
                 * `var x,y`
                 * tokenAfterDeclarator ^^ afterComma
                 */
                if (afterComma.range[0] === tokenAfterDeclarator.range[1]) {
                    return fixer.replaceText(tokenAfterDeclarator, `; ${declaration.kind} `);
                }

                /*
                 * `var x,
                 * tokenAfterDeclarator ^
                 *      y`
                 *      ^ afterComma
                 */
                if (
                    afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line ||
                    afterComma.type === "Line" ||
                    afterComma.type === "Block"
                ) {
                    let lastComment = afterComma;

                    while (lastComment.type === "Line" || lastComment.type === "Block") {
                        lastComment = sourceCode.getTokenAfter(lastComment, { includeComments: true });
                    }

                    return fixer.replaceTextRange(
                        [tokenAfterDeclarator.range[0], lastComment.range[0]],
                        `;${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}${declaration.kind} `
                    );
                }

                return fixer.replaceText(tokenAfterDeclarator, `; ${declaration.kind}`);
            }).filter(x => x);
        }
function splitDeclarations(declaration) {
            return fixer => declaration.declarations.map(declarator => {
                const tokenAfterDeclarator = sourceCode.getTokenAfter(declarator);

                if (tokenAfterDeclarator === null) {
                    return null;
                }

                const afterComma = sourceCode.getTokenAfter(tokenAfterDeclarator, { includeComments: true });

                if (tokenAfterDeclarator.value !== ",") {
                    return null;
                }

                /*
                 * `var x,y`
                 * tokenAfterDeclarator ^^ afterComma
                 */
                if (afterComma.range[0] === tokenAfterDeclarator.range[1]) {
                    return fixer.replaceText(tokenAfterDeclarator, `; ${declaration.kind} `);
                }

                /*
                 * `var x,
                 * tokenAfterDeclarator ^
                 *      y`
                 *      ^ afterComma
                 */
                if (
                    afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line ||
                    afterComma.type === "Line" ||
                    afterComma.type === "Block"
                ) {
                    let lastComment = afterComma;

                    while (lastComment.type === "Line" || lastComment.type === "Block") {
                        lastComment = sourceCode.getTokenAfter(lastComment, { includeComments: true });
                    }

                    return fixer.replaceTextRange(
                        [tokenAfterDeclarator.range[0], lastComment.range[0]],
                        `;${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}${declaration.kind} `
                    );
                }

                return fixer.replaceText(tokenAfterDeclarator, `; ${declaration.kind}`);
            }).filter(x => x);
        }
function splitDeclarations ( declaration ) { return fixer => declaration . declarations . map ( declarator => { const tokenAfterDeclarator = sourceCode . getTokenAfter ( declarator ) ; if ( tokenAfterDeclarator === null ) { return null ; } const afterComma = sourceCode . getTokenAfter ( tokenAfterDeclarator , { includeComments : true } ) ; if ( tokenAfterDeclarator . value !== "," ) { return null ; } /*
                 * `var x,y`
                 * tokenAfterDeclarator ^^ afterComma
                 */ if ( afterComma . range [ 0 ] === tokenAfterDeclarator . range [ 1 ] ) { return fixer . replaceText ( tokenAfterDeclarator , ` ${ declaration . kind } ` ) ; } /*
                 * `var x,
                 * tokenAfterDeclarator ^
                 *      y`
                 *      ^ afterComma
                 */ if ( afterComma . loc . start . line > tokenAfterDeclarator . loc . end . line || afterComma . type === "Line" || afterComma . type === "Block" ) { let lastComment = afterComma ; while ( lastComment . type === "Line" || lastComment . type === "Block" ) { lastComment = sourceCode . getTokenAfter ( lastComment , { includeComments : true } ) ; } return fixer . replaceTextRange ( [ tokenAfterDeclarator . range [ 0 ] , lastComment . range [ 0 ] ] , ` ${ sourceCode . text . slice ( tokenAfterDeclarator . range [ 1 ] , lastComment . range [ 0 ] ) } ${ declaration . kind } ` ) ; } return fixer . replaceText ( tokenAfterDeclarator , ` ${ declaration . kind } ` ) ; } ) . filter ( x => x ) ; }
Fixer to split a VariableDeclaration into individual declarations
@param   {VariableDeclaration}   declaration The `VariableDeclaration` to split
@returns {Function}                          The fixer function
Fixer to split a VariableDeclaration into individual declarations