no-iterator.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @fileoverview Rule to flag usage of __iterator__ property
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const { getStaticPropertyName } = require("./utils/ast-utils");
  10. //------------------------------------------------------------------------------
  11. // Rule Definition
  12. //------------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. type: "suggestion",
  16. docs: {
  17. description: "disallow the use of the `__iterator__` property",
  18. category: "Best Practices",
  19. recommended: false,
  20. url: "https://eslint.org/docs/rules/no-iterator"
  21. },
  22. schema: [],
  23. messages: {
  24. noIterator: "Reserved name '__iterator__'."
  25. }
  26. },
  27. create(context) {
  28. return {
  29. MemberExpression(node) {
  30. if (getStaticPropertyName(node) === "__iterator__") {
  31. context.report({
  32. node,
  33. messageId: "noIterator"
  34. });
  35. }
  36. }
  37. };
  38. }
  39. };