await-fire-event.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.RULE_NAME = void 0;
  4. var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
  5. var utils_1 = require("../utils");
  6. var node_utils_1 = require("../node-utils");
  7. exports.RULE_NAME = 'await-fire-event';
  8. exports.default = experimental_utils_1.ESLintUtils.RuleCreator(utils_1.getDocsUrl)({
  9. name: exports.RULE_NAME,
  10. meta: {
  11. type: 'problem',
  12. docs: {
  13. description: 'Enforce async fire event methods to be awaited',
  14. category: 'Best Practices',
  15. recommended: false,
  16. },
  17. messages: {
  18. awaitFireEvent: 'async `fireEvent.{{ methodName }}` must be awaited',
  19. },
  20. fixable: null,
  21. schema: [],
  22. },
  23. defaultOptions: [],
  24. create: function (context) {
  25. return {
  26. 'CallExpression > MemberExpression > Identifier[name=fireEvent]': function (node) {
  27. var memberExpression = node.parent;
  28. var fireEventMethodNode = memberExpression.property;
  29. if (node_utils_1.isIdentifier(fireEventMethodNode) &&
  30. !node_utils_1.isAwaited(node.parent.parent.parent) &&
  31. !node_utils_1.isPromiseResolved(fireEventMethodNode.parent)) {
  32. context.report({
  33. node: fireEventMethodNode,
  34. messageId: 'awaitFireEvent',
  35. data: {
  36. methodName: fireEventMethodNode.name,
  37. },
  38. });
  39. }
  40. },
  41. };
  42. },
  43. });