2 * @fileoverview Rule to flag creation of function inside a loop
4 * @copyright 2013 Ilya Volodin. All rights reserved.
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 module.exports = function(context) {
23 * Checks if the given node is a loop.
24 * @param {ASTNode} node The AST node to check.
25 * @returns {boolean} Whether or not the node is a loop.
27 function isLoop(node) {
28 return loopNodeTypes.indexOf(node.type) > -1;
32 * Reports if the given node has an ancestor node which is a loop.
33 * @param {ASTNode} node The AST node to check.
34 * @returns {boolean} Whether or not the node is within a loop.
36 function checkForLoops(node) {
37 var ancestors = context.getAncestors();
39 if (ancestors.some(isLoop)) {
40 context.report(node, "Don't make functions within a loop");
45 "ArrowFunctionExpression": checkForLoops,
46 "FunctionExpression": checkForLoops,
47 "FunctionDeclaration": checkForLoops