Repository: eslint/eslint
File: lib/source-code/source-code.js (JavaScript)

Code before:

        for (let node = currentNode; node; node = node.parent) {
            const scope = this.scopeManager.acquire(node, inner);

            if (scope) {
                if (scope.type === "function-expression-name") {
                    cache.set(currentNode, scope.childScopes[0]);
                    return scope.childScopes[0];
                }

                cache.set(currentNode, scope);
                return scope;
            }
        }

        cache.set(currentNode, this.scopeManager.scopes[0]);
        return this.scopeManager.scopes[0];
    }

    /**
     * Gets all of the declared variables in the scope represented
     * by `node`. This is a convenience method that passes through
     * to the same method on the `scopeManager`.
     * @param {ASTNode} node The node representing the scope to check.
     * @returns {Array<Variable>} An array of variable nodes representing
     *      the declared variables in the scope.
     */
    getDeclaredVariables(node) {
        return this.scopeManager.getDeclaredVariables(node);
    }

    /**
     * Gets all the ancestors of a given node
     * @param {ASTNode} node The node
     * @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting
     * from the root node at index 0 and going inwards to the parent node.
     */
    getAncestors(node) {

        const cache = this[caches].get("ancestors");
        const cachedAncestry = cache.get(node);

        /*
         * Important! The array returned from this method must be mutable
         * without side effects, meaning each rule must receive its own copy
         * of the array that it can mutate without affecting other rules.
         * Historically, this method calculated and returned a new array for
         * each call, but that's pretty inefficient. So we cache the result
         * and then create a new array with the same elements here.
         */
        if (cachedAncestry) {

Review comment (suggestion):
```suggestion
     * @returns {Array<Variable>} An array of variables declared by `node`.
```

Same as above.

Code after:
        for (let node = currentNode; node; node = node.parent) {
            const scope = this.scopeManager.acquire(node, inner);

            if (scope) {
                if (scope.type === "function-expression-name") {
                    cache.set(currentNode, scope.childScopes[0]);
                    return scope.childScopes[0];
                }

                cache.set(currentNode, scope);
                return scope;
            }
        }

        cache.set(currentNode, this.scopeManager.scopes[0]);
        return this.scopeManager.scopes[0];
    }

    /**
     * Gets all of the declared variables in the scope associated
     * with `node`. This is a convenience method that passes through
     * to the same method on the `scopeManager`.
     * @param {ASTNode} node The node from which to retrieve the scope to check.
     * @returns {Array<Variable>} An array of variable nodes representing
     *      the declared variables in the scope associated with `node`.
     */
    getDeclaredVariables(node) {
        return this.scopeManager.getDeclaredVariables(node);
    }

    /* eslint-disable class-methods-use-this -- node is owned by SourceCode */
    /**
     * Gets all the ancestors of a given node
     * @param {ASTNode} node The node
     * @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting
     * from the root node at index 0 and going inwards to the parent node.
     * @throws {TypeError} When `node` is missing.
     */
    getAncestors(node) {

        if (!node) {
            throw new TypeError("Missing required argument: node.");
        }

        const ancestorsStartingAtParent = [];

        for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
            ancestorsStartingAtParent.push(ancestor);
        }

        return ancestorsStartingAtParent.reverse();