no-iterator.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @fileoverview Rule to flag usage of __iterator__ property
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow the use of the `__iterator__` property",
  13. category: "Best Practices",
  14. recommended: false,
  15. url: "https://eslint.org/docs/rules/no-iterator"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. return {
  21. MemberExpression(node) {
  22. if (node.property &&
  23. (node.property.type === "Identifier" && node.property.name === "__iterator__" && !node.computed) ||
  24. (node.property.type === "Literal" && node.property.value === "__iterator__")) {
  25. context.report({ node, message: "Reserved name '__iterator__'." });
  26. }
  27. }
  28. };
  29. }
  30. };