项目原始demo,不改动
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. };