UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when using new Function
3 * @author Ilya Volodin
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = function(context) {
13
14 //--------------------------------------------------------------------------
15 // Helpers
16 //--------------------------------------------------------------------------
17
18 /**
19 * Checks if the callee is the Function constructor, and if so, reports an issue.
20 * @param {ASTNode} node The node to check and report on
21 * @returns {void}
22 * @private
23 */
24 function validateCallee(node) {
25 if (node.callee.name === "Function") {
26 context.report(node, "The Function constructor is eval.");
27 }
28 }
29
30 return {
31 "NewExpression": validateCallee,
32 "CallExpression": validateCallee
33 };
34
35};
36
37module.exports.schema = [];