function walk()

in src/tslint/incorrectStateAccessRule.ts [81:128]


function walk(ctx: Lint.WalkContext<string[]>): void {
    return ts.forEachChild(ctx.sourceFile, function cb(node): void {
        if (isMethodDeclaration(node)) {
            const methodName = node.name.getText();
            method = { name: methodName, calling: [], node, stateNodes: [] };
            methods[node.name.getText()] = method;
            if (node.body) {
                analyzeMethodBody(node.body);
            }
        } else if (node.kind === ts.SyntaxKind.EndOfFileToken) {
            // End of file. Use collected information to analyze function call graph starting from willComponentMount
            const visitedMethods: {[key: string]: boolean} = {};
            const queue: MethodInfo[] = [];

            const methodsList = ctx.options.concat(['UNSAFE_componentWillMount']);

            methodsList.forEach((methodName: string) => {
                const method =  methods[methodName];
                if (method) {
                    queue.push(method);
                }
            });

            while (queue.length > 0) {
                const method = queue.pop()!!!;

                if (!visitedMethods[method.name]) {
                    visitedMethods[method.name] = true;
                    method.stateNodes.forEach((node: ts.Node) => {
                        ctx.addFailureAtNode(node, ERROR_MESSAGE);
                    });

                    method.calling.forEach((name: string) => {
                        const called = methods[name];
                        if (called) {
                            queue.push(called);
                        }
                    });
                }
            }

            // clean up
            methods = {};
        } else {
            return ts.forEachChild(node, cb);
        }
    });
}