reject-global-this.js 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * @fileoverview Reject attempts to use the global object in jsms.
  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. const helpers = require("../helpers");
  10. // -----------------------------------------------------------------------------
  11. // Rule Definition
  12. // -----------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. url:
  17. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/reject-global-this.html",
  18. },
  19. type: "problem",
  20. },
  21. create(context) {
  22. return {
  23. ThisExpression(node) {
  24. if (!helpers.getIsGlobalThis(context.getAncestors())) {
  25. return;
  26. }
  27. context.report({
  28. node,
  29. message: `JSM should not use the global this`,
  30. });
  31. },
  32. };
  33. },
  34. };