no-proto.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @fileoverview Rule to flag usage of __proto__ property
  3. * @author Ilya Volodin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const { getStaticPropertyName } = require("./utils/ast-utils");
  10. //------------------------------------------------------------------------------
  11. // Rule Definition
  12. //------------------------------------------------------------------------------
  13. /** @type {import('../shared/types').Rule} */
  14. module.exports = {
  15. meta: {
  16. type: "suggestion",
  17. docs: {
  18. description: "Disallow the use of the `__proto__` property",
  19. recommended: false,
  20. url: "https://eslint.org/docs/rules/no-proto"
  21. },
  22. schema: [],
  23. messages: {
  24. unexpectedProto: "The '__proto__' property is deprecated."
  25. }
  26. },
  27. create(context) {
  28. return {
  29. MemberExpression(node) {
  30. if (getStaticPropertyName(node) === "__proto__") {
  31. context.report({ node, messageId: "unexpectedProto" });
  32. }
  33. }
  34. };
  35. }
  36. };