no-new-require.js 1.2 KB

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