项目原始demo,不改动
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.
 
 
 
 

45 Zeilen
1.2 KiB

  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. docs: {
  12. description: "disallow `new` operators with the `Symbol` object",
  13. category: "ECMAScript 6",
  14. recommended: true,
  15. url: "https://eslint.org/docs/rules/no-new-symbol"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. return {
  21. "Program:exit"() {
  22. const globalScope = context.getScope();
  23. const variable = globalScope.set.get("Symbol");
  24. if (variable && variable.defs.length === 0) {
  25. variable.references.forEach(ref => {
  26. const node = ref.identifier;
  27. if (node.parent && node.parent.type === "NewExpression") {
  28. context.report({ node, message: "`Symbol` cannot be called as a constructor." });
  29. }
  30. });
  31. }
  32. }
  33. };
  34. }
  35. };