no-await-sync-query.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. exports.RULE_NAME = 'no-await-sync-query';
  7. var SYNC_QUERIES_REGEXP = /^(get|query)(All)?By(LabelText|PlaceholderText|Text|AltText|Title|DisplayValue|Role|TestId)$/;
  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: 'Disallow unnecessary `await` for sync queries',
  14. category: 'Best Practices',
  15. recommended: 'error',
  16. },
  17. messages: {
  18. noAwaitSyncQuery: '`{{ name }}` does not need `await` operator',
  19. },
  20. fixable: null,
  21. schema: [],
  22. },
  23. defaultOptions: [],
  24. create: function (context) {
  25. var _a;
  26. var reportError = function (node) {
  27. return context.report({
  28. node: node,
  29. messageId: 'noAwaitSyncQuery',
  30. data: {
  31. name: node.name,
  32. },
  33. });
  34. };
  35. return _a = {},
  36. _a["AwaitExpression > CallExpression > Identifier[name=" + SYNC_QUERIES_REGEXP + "]"] = reportError,
  37. _a["AwaitExpression > CallExpression > MemberExpression > Identifier[name=" + SYNC_QUERIES_REGEXP + "]"] = reportError,
  38. _a;
  39. },
  40. });