{"record":{"id":"e35c9ddae96b3ccf","repo":"oxc-project/oxc","slug":"don-t-return-in-a-finally-callback","errorCode":null,"errorMessage":"Don't return in a finally callback","messagePattern":"Don't return in a finally callback","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/promise/no_return_in_finally.rs","lineNumber":12,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, FunctionBody, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_promise};\n\nfn no_return_in_finally_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Don't return in a finally callback\")\n        .with_help(\"Remove the return statement as nothing can consume the return value\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoReturnInFinally;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow return statements in a `finally()` callback of a promise.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Disallow return statements inside a callback passed to finally(), since nothing would\n    /// consume what's returned.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/promise/no_return_in_finally.rs#L1-L30","documentation":"Diagnostic from the oxlint rule `promise/no-return-in-finally` (plugin `promise`). It flags any `return` statement inside the callback of a `.finally()` (member call recognized by `is_promise`). A finally callback cannot alter the settled outcome of the chain: the returned value is discarded, so the return is dead code that misleads readers into thinking something consumes it.","triggerScenarios":"`p.finally(() => { return cleanup() })`; `p.finally(function () { return; })` inside a promise chain.","commonSituations":"Cleanup callbacks written by habit with implicit or explicit returns; converting synchronous `try/finally` helpers into `.finally()`; arrow functions whose body is a single expression (implicit return).","solutions":["Remove the `return` so the callback only performs side effects","Use a block body for arrow callbacks: `p.finally(() => { cleanup() })` instead of `p.finally(() => cleanup())`","If you need the value afterwards, move the logic to a `.then()` before the `.finally()`"],"exampleFix":"// before\np.finally(() => {\n  return cleanup()\n})\n\n// after\np.finally(() => {\n  cleanup()\n})","handlingStrategy":"validation","validationCode":"npx oxlint --promise/no-return-in-finally src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `.finally()` callbacks as side-effect-only blocks with no `return`","Use block-bodied arrows in cleanup callbacks to avoid implicit returns","Put value-producing logic in `.then()`, not `.finally()`"],"tags":["promise","async","lint","code-style","oxlint"],"backgroundTag":"return-in-finally","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"}