UNPKG

935 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag use of implied eval via setTimeout and setInterval
3 * @author James Allardice
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15 "CallExpression": function(node) {
16
17 if (node.callee.type === "Identifier") {
18 var callee = node.callee.name;
19
20 if (callee === "setTimeout" || callee === "setInterval") {
21 var argument = node.arguments[0];
22 if (argument && argument.type === "Literal" && typeof argument.value === "string") {
23 context.report(node, "Implied eval. Consider passing a function instead of a string.");
24 }
25 }
26 }
27 }
28 };
29
30};