lib/rules/no-inner-declarations.js
function nearestBody() {
            const ancestors = context.getAncestors();
            let ancestor = ancestors.pop(),
                generation = 1;

            while (ancestor && ["Program", "FunctionDeclaration",
                "FunctionExpression", "ArrowFunctionExpression"
            ].indexOf(ancestor.type) < 0) {
                generation += 1;
                ancestor = ancestors.pop();
            }

            return {

                // Type of containing ancestor
                type: ancestor.type,

                // Separation between ancestor and node
                distance: generation
            };
        }
function nearestBody() {
            const ancestors = context.getAncestors();
            let ancestor = ancestors.pop(),
                generation = 1;

            while (ancestor && ["Program", "FunctionDeclaration",
                "FunctionExpression", "ArrowFunctionExpression"
            ].indexOf(ancestor.type) < 0) {
                generation += 1;
                ancestor = ancestors.pop();
            }

            return {

                // Type of containing ancestor
                type: ancestor.type,

                // Separation between ancestor and node
                distance: generation
            };
        }
function nearestBody ( ) { const ancestors = context . getAncestors ( ) ; let ancestor = ancestors . pop ( ) , generation = 1 ; while ( ancestor && [ "Program" , "FunctionDeclaration" , "FunctionExpression" , "ArrowFunctionExpression" ] . indexOf ( ancestor . type ) < 0 ) { generation += 1 ; ancestor = ancestors . pop ( ) ; } return { // Type of containing ancestor type : ancestor . type , // Separation between ancestor and node distance : generation } ; }
Find the nearest Program or Function ancestor node.
@returns {Object} Ancestor's type and distance from node.
Find the nearest Program or Function ancestor node .