no-new.js 884 B

12345678910111213141516171819202122232425262728293031323334
  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. module.exports = {
  11. meta: {
  12. docs: {
  13. description: "disallow `new` operators outside of assignments or comparisons",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-new"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. return {
  22. "ExpressionStatement > NewExpression"(node) {
  23. context.report({ node: node.parent, message: "Do not use 'new' for side effects." });
  24. }
  25. };
  26. }
  27. };