no-new.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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('../shared/types').Rule} */
  11. module.exports = {
  12. meta: {
  13. type: "suggestion",
  14. docs: {
  15. description: "Disallow `new` operators outside of assignments or comparisons",
  16. recommended: false,
  17. url: "https://eslint.org/docs/rules/no-new"
  18. },
  19. schema: [],
  20. messages: {
  21. noNewStatement: "Do not use 'new' for side effects."
  22. }
  23. },
  24. create(context) {
  25. return {
  26. "ExpressionStatement > NewExpression"(node) {
  27. context.report({
  28. node: node.parent,
  29. messageId: "noNewStatement"
  30. });
  31. }
  32. };
  33. }
  34. };