{"record":{"id":"69f900969e12acbc","repo":"oxc-project/oxc","slug":"promise-executor-functions-should-not-be-async","errorCode":null,"errorMessage":"Promise executor functions should not be `async`.","messagePattern":"Promise executor functions should not be `async`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs","lineNumber":12,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_async_promise_executor_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Promise executor functions should not be `async`.\")\n        .with_help(\"Remove the `async` keyword from the Promise executor function.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoAsyncPromiseExecutor;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow using an async function as a Promise executor.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `new Promise` constructor accepts an executor function as an argument,\n    /// which has `resolve` and `reject` parameters that can be used to control the state of the\n    /// created Promise. For example:\n    /// ```javascript","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs#L1-L30","documentation":"Diagnostic from the oxlint rule `no-async-promise-executor` (eslint plugin, crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs). It fires when the executor function passed to `new Promise(...)` is declared `async`. The Promise constructor ignores the executor's returned promise, so an async executor that throws produces an unhandled rejection instead of rejecting the constructed promise, and resolution ordering can silently diverge from what the code implies.","triggerScenarios":"Any node matching `new Promise(async (resolve, reject) => {...})` or `new Promise(async function (resolve, reject) {...})` — i.e. the first Argument of a NewExpression whose callee resolves to global `Promise` is a FunctionExpression/ArrowFunctionExpression with an async marker.","commonSituations":"Refactoring promise chains into async/await and leaving the async keyword on the executor; copy-pasting an async helper into a Promise constructor; code migrated from ESLint projects where the same rule already flagged it; enabling the `correctness` category of oxlint on an existing codebase.","solutions":["Remove the `async` keyword from the executor and use plain `.then()` chains or call an async helper inside, e.g. `new Promise((resolve, reject) => { doAsync().then(resolve, reject); })`.","If the body awaits several steps, hoist them into a separate async function and call it from a non-async executor.","If the whole Promise wrapper is unnecessary, return the async function's promise directly instead of wrapping it in `new Promise`.","If the pattern is intentional and handled, suppress with an inline `// oxlint-disable-next-line no-async-promise-executor` comment."],"exampleFix":"// before\nconst p = new Promise(async (resolve, reject) => {\n  const data = await fetchData();\n  resolve(data);\n});\n\n// after\nconst p = new Promise((resolve, reject) => {\n  fetchData().then(resolve, reject);\n});","handlingStrategy":"validation","validationCode":"// Pre-check before lint: flag async executors before they ship\nconst src = fs.readFileSync(file, 'utf8');\nconst badAsyncExecutor = /new\\s+Promise\\s*\\(\\s*async\\b/.test(src);\nif (badAsyncExecutor) failFast('async Promise executor in ' + file);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `new Promise(...)` as a last resort; prefer async functions that return values directly.","Enable the eslint `correctness` category in oxlint so this is caught at commit time.","In review, grep new PRs for `new Promise\\s*\\(\\s*async`."],"tags":["lint","promise","async","unhandled-rejection","oxlint"],"backgroundTag":"async-promise-executor","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}