no-async-promise-executor.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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('../shared/types').Rule} */
  10. module.exports = {
  11. meta: {
  12. type: "problem",
  13. docs: {
  14. description: "Disallow using an async function as a Promise executor",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-async-promise-executor"
  17. },
  18. fixable: null,
  19. schema: [],
  20. messages: {
  21. async: "Promise executor functions should not be async."
  22. }
  23. },
  24. create(context) {
  25. return {
  26. "NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) {
  27. context.report({
  28. node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"),
  29. messageId: "async"
  30. });
  31. }
  32. };
  33. }
  34. };