reject-top-level-await.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview Don't allow only() in tests
  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. var helpers = require("../helpers");
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. url:
  14. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/reject-top-level-await.html",
  15. },
  16. messages: {
  17. rejectTopLevelAwait:
  18. "Top-level await is not currently supported in component files.",
  19. },
  20. type: "problem",
  21. },
  22. create(context) {
  23. return {
  24. AwaitExpression(node) {
  25. if (!helpers.getIsTopLevelScript(context.getAncestors())) {
  26. return;
  27. }
  28. context.report({ node, messageId: "rejectTopLevelAwait" });
  29. },
  30. ForOfStatement(node) {
  31. if (
  32. !node.await ||
  33. !helpers.getIsTopLevelScript(context.getAncestors())
  34. ) {
  35. return;
  36. }
  37. context.report({ node, messageId: "rejectTopLevelAwait" });
  38. },
  39. };
  40. },
  41. };