Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-new-symbol.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @fileoverview Rule to disallow use of the new operator with the `Symbol` object
  3. * @author Alberto Rodríguez
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "problem",
  12. docs: {
  13. description: "disallow `new` operators with the `Symbol` object",
  14. category: "ECMAScript 6",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-new-symbol"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. return {
  22. "Program:exit"() {
  23. const globalScope = context.getScope();
  24. const variable = globalScope.set.get("Symbol");
  25. if (variable && variable.defs.length === 0) {
  26. variable.references.forEach(ref => {
  27. const node = ref.identifier;
  28. if (node.parent && node.parent.type === "NewExpression") {
  29. context.report({ node, message: "`Symbol` cannot be called as a constructor." });
  30. }
  31. });
  32. }
  33. }
  34. };
  35. }
  36. };