no-new-require.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @fileoverview Rule to disallow use of new operator with the `require` function
  3. * @author Wil Moore III
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. deprecated: true,
  12. replacedBy: [],
  13. type: "suggestion",
  14. docs: {
  15. description: "disallow `new` operators with calls to `require`",
  16. category: "Node.js and CommonJS",
  17. recommended: false,
  18. url: "https://eslint.org/docs/rules/no-new-require"
  19. },
  20. schema: [],
  21. messages: {
  22. noNewRequire: "Unexpected use of new with require."
  23. }
  24. },
  25. create(context) {
  26. return {
  27. NewExpression(node) {
  28. if (node.callee.type === "Identifier" && node.callee.name === "require") {
  29. context.report({
  30. node,
  31. messageId: "noNewRequire"
  32. });
  33. }
  34. }
  35. };
  36. }
  37. };