no-async-promise-executor.js 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview disallow using an async function as a Promise executor
  3. * @author Teddy Katz
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. /** @type {import('../types').Rule.RuleModule} */
  10. module.exports = {
  11. meta: {
  12. type: "problem",
  13. docs: {
  14. description:
  15. "Disallow using an async function as a Promise executor",
  16. recommended: true,
  17. url: "https://eslint.org/docs/latest/rules/no-async-promise-executor",
  18. },
  19. fixable: null,
  20. schema: [],
  21. messages: {
  22. async: "Promise executor functions should not be async.",
  23. },
  24. },
  25. create(context) {
  26. return {
  27. "NewExpression[callee.name='Promise'][arguments.0.async=true]"(
  28. node,
  29. ) {
  30. context.report({
  31. node: context.sourceCode.getFirstToken(
  32. node.arguments[0],
  33. token => token.value === "async",
  34. ),
  35. messageId: "async",
  36. });
  37. },
  38. };
  39. },
  40. };