github-pages-deploy-action/node_modules/eslint/lib/rules/no-new-func.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview Rule to flag when using new Function
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow `new` operators with the `Function` object",
category: "Best Practices",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-func"
},
2020-05-15 05:33:08 +08:00
schema: [],
messages: {
noFunctionConstructor: "The Function constructor is eval."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
/**
* Reports a node.
* @param {ASTNode} node The node to report
* @returns {void}
* @private
*/
function report(node) {
2020-05-15 05:33:08 +08:00
context.report({
node,
messageId: "noFunctionConstructor"
});
2020-03-07 11:45:40 +08:00
}
return {
"NewExpression[callee.name = 'Function']": report,
"CallExpression[callee.name = 'Function']": report
};
}
};