no-new.js 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @fileoverview Rule to flag statements with function invocation preceded by
  3. * "new" and not part of assignment
  4. * @author Ilya Volodin
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. /** @type {import('../types').Rule.RuleModule} */
  11. module.exports = {
  12. meta: {
  13. type: "suggestion",
  14. docs: {
  15. description:
  16. "Disallow `new` operators outside of assignments or comparisons",
  17. recommended: false,
  18. url: "https://eslint.org/docs/latest/rules/no-new",
  19. },
  20. schema: [],
  21. messages: {
  22. noNewStatement: "Do not use 'new' for side effects.",
  23. },
  24. },
  25. create(context) {
  26. return {
  27. "ExpressionStatement > NewExpression"(node) {
  28. context.report({
  29. node: node.parent,
  30. messageId: "noNewStatement",
  31. });
  32. },
  33. };
  34. },
  35. };