Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-new-func.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @fileoverview Rule to flag when using new Function
  3. * @author Ilya Volodin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow `new` operators with the `Function` object",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-new-func"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. //--------------------------------------------------------------------------
  22. // Helpers
  23. //--------------------------------------------------------------------------
  24. /**
  25. * Reports a node.
  26. * @param {ASTNode} node The node to report
  27. * @returns {void}
  28. * @private
  29. */
  30. function report(node) {
  31. context.report({ node, message: "The Function constructor is eval." });
  32. }
  33. return {
  34. "NewExpression[callee.name = 'Function']": report,
  35. "CallExpression[callee.name = 'Function']": report
  36. };
  37. }
  38. };