1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | "use strict";
|
13 |
|
14 | function checkForLoops(node) {
|
15 | var ancestors = context.getAncestors();
|
16 |
|
17 | if (ancestors.some(function(ancestor) {
|
18 | return ancestor.type === "ForStatement" || ancestor.type === "WhileStatement" || ancestor.type === "DoWhileStatement";
|
19 | })) {
|
20 | context.report(node, "Don't make functions within a loop");
|
21 | }
|
22 | }
|
23 |
|
24 | return {
|
25 | "FunctionExpression": checkForLoops,
|
26 | "FunctionDeclaration": checkForLoops
|
27 | };
|
28 | };
|