no-object-getownpropertydescriptors.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.getOwnPropertyDescriptors` method.",
  12. category: "ES2017",
  13. recommended: false,
  14. url:
  15. "http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertydescriptors.html",
  16. },
  17. fixable: null,
  18. schema: [],
  19. messages: {
  20. forbidden: "ES2017 '{{name}}' method is forbidden.",
  21. },
  22. },
  23. create(context) {
  24. return {
  25. "Program:exit"() {
  26. const tracker = new ReferenceTracker(context.getScope())
  27. for (const { node, path } of tracker.iterateGlobalReferences({
  28. Object: {
  29. getOwnPropertyDescriptors: { [READ]: true },
  30. },
  31. })) {
  32. context.report({
  33. node,
  34. messageId: "forbidden",
  35. data: { name: path.join(".") },
  36. })
  37. }
  38. },
  39. }
  40. },
  41. }