{"record":{"id":"720fb86ad547f1e3","repo":"oxc-project/oxc","slug":"avoid-using-promises-inside-of-callbacks","errorCode":null,"errorMessage":"Avoid using promises inside of callbacks.","messagePattern":"Avoid using promises inside of callbacks\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs","lineNumber":16,"sourceCode":"use oxc_ast::{AstKind, ast::FormalParameters};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_promise,\n};\n\nfn no_promise_in_callback_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Avoid using promises inside of callbacks.\")\n        .with_help(\"Use either promises or callbacks exclusively for handling asynchronous code.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct NoPromiseInCallbackConfig {\n    /// Whether or not to exempt function declarations. Defaults to `false`.\n    exempt_declarations: bool,\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\npub struct NoPromiseInCallback(NoPromiseInCallbackConfig);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows the use of Promises within error-first callback functions.","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs#L1-L34","documentation":"Diagnostic from the oxlint rule `promise/no-promise-in-callback` (plugin `promise`, category `suspicious`). It fires when a promise-returning call (per `is_promise`) appears inside an ancestor function identified as an error-first callback - a function-like node whose first parameter is the conventional error parameter. The rule exempts promise calls that are the direct argument of a `return` statement (chain links, per the comment in the source) and promise handlers themselves; the `exemptDeclarations` option (default `false`) additionally skips function declarations. Mixing the two async styles makes error handling inconsistent: callbacks use error-first, promises use `catch`.","triggerScenarios":"`doSomething((err, data) => doSomethingElse(data).then(render))` - the promise call is inside an `(err, ...) =>` callback and not in return position.","commonSituations":"Layering promise-based APIs on top of callback-based libraries (fs, events, older SDKs) during incremental migration; codebases mid-transition between styles.","solutions":["Promisify the outer API and use one style end to end: `promisify(doSomething)().then(doSomethingElse).then(render)`","Commit to callbacks fully inside the callback and convert at the boundary","Set `{ \"exemptDeclarations\": true }` if your function declarations are module entry points, not callbacks","Wrap only at the outermost boundary and keep inner code promise-only"],"exampleFix":"// before\ndoSomething((err, data) => {\n  if (err) console.error(err)\n  else doSomethingElse(data).then(console.log)\n})\n\n// after\nconst { promisify } = require('util')\npromisify(doSomething)()\n  .then(doSomethingElse)\n  .then(console.log)\n  .catch(console.error)","handlingStrategy":"validation","validationCode":"npx oxlint --promise/no-promise-in-callback src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert at boundaries: promisify the callback API once, then stay promise-only inside","Reserve `(err, value) =>` signatures for pure callback code","If function declarations are entry points, set `exemptDeclarations: true` deliberately, not silently"],"tags":["promise","async","callback","lint","oxlint"],"backgroundTag":"mixing-promises-and-callbacks","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}