no-object-getownpropertydescriptor.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { READ, ReferenceTracker } = require("eslint-utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description:
  11. "disallow the `Object.getOwnPropertyDescriptor` method.",
  12. category: "ES5",
  13. recommended: false,
  14. url:
  15. "http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertydescriptor.html",
  16. },
  17. fixable: null,
  18. messages: {
  19. forbidden: "ES5 '{{name}}' method is forbidden.",
  20. },
  21. schema: [],
  22. type: "problem",
  23. },
  24. create(context) {
  25. return {
  26. "Program:exit"() {
  27. const tracker = new ReferenceTracker(context.getScope())
  28. for (const { node, path } of tracker.iterateGlobalReferences({
  29. Object: {
  30. getOwnPropertyDescriptor: { [READ]: true },
  31. },
  32. })) {
  33. context.report({
  34. node,
  35. messageId: "forbidden",
  36. data: { name: path.join(".") },
  37. })
  38. }
  39. },
  40. }
  41. },
  42. }