use-ownerGlobal.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * @fileoverview Require .ownerGlobal instead of .ownerDocument.defaultView.
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. "use strict";
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. url:
  13. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/use-ownerGlobal.html",
  14. },
  15. type: "suggestion",
  16. },
  17. create(context) {
  18. return {
  19. MemberExpression(node) {
  20. if (
  21. node.property.type != "Identifier" ||
  22. node.property.name != "defaultView" ||
  23. node.object.type != "MemberExpression" ||
  24. node.object.property.type != "Identifier" ||
  25. node.object.property.name != "ownerDocument"
  26. ) {
  27. return;
  28. }
  29. context.report(
  30. node,
  31. "use .ownerGlobal instead of .ownerDocument.defaultView"
  32. );
  33. },
  34. };
  35. },
  36. };