{"record":{"id":"6da3f88b002ec1a6","repo":"oxc-project/oxc","slug":"unnecessary-return-statement","errorCode":null,"errorMessage":"Unnecessary return statement.","messagePattern":"Unnecessary return statement\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_return.rs","lineNumber":16,"sourceCode":"use oxc_allocator::ArenaVec;\nuse oxc_ast::AstKind;\nuse oxc_cfg::{\n    BlockNodeId, ControlFlowGraph, EdgeType, InstructionKind, ReturnInstructionKind,\n    graph::{Direction, visit::EdgeRef},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_useless_return_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unnecessary return statement.\")\n        .with_help(\"Remove this redundant `return` statement.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessReturn;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows redundant return statements.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// A `return;` statement with nothing after it is redundant, and has no effect\n    /// on the runtime behavior of a function. This can be confusing, so it's better\n    /// to disallow these redundant statements.\n    ///","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_return.rs#L1-L34","documentation":"Diagnostic from the `no-useless-return` rule. A `return;` (or `return undefined;`) statement at the end of a function adds nothing because falling off the end already returns undefined. Oxc implements this on the semantic CFG (ControlFlowGraph edges/instructions), reporting return instructions that are the terminal no-op of their function. Help text: 'Remove this redundant `return` statement.'","triggerScenarios":"`function f() { doWork(); return; }`, arrow bodies with trailing `return;`, or `return undefined;` as the last statement. The rule walks CFG return instructions and flags those with no value that lead directly to the function exit.","commonSituations":"Leftover early-return style from C/Java habits; refactors that removed code after return; guard clauses moved so a final bare return remains.","solutions":["Delete the trailing `return;` statement.","If the return documented intent, add a comment instead of dead code.","For `return undefined;` mid-function that is meaningful control flow, keep it but ensure it is not the last statement.","Use `oxlint --fix` which removes the statement automatically."],"exampleFix":"// before\nfunction save(data) {\n  persist(data);\n  return;\n}\n\n// after\nfunction save(data) {\n  persist(data);\n}","handlingStrategy":"validation","validationCode":"// heuristic: flag a bare `return;` that is the last statement of a function body\nfunction hasTrailingBareReturn(fnSource) {\n  return /\\breturn\\s*;?\\s*\\}\\s*$/.test(fnSource);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["End functions without a trailing bare `return;`.","Use early returns with values, not terminal no-op returns.","Run `oxlint --fix` to strip them mechanically during refactors."],"tags":["lint","eslint","oxlint","control-flow","return"],"backgroundTag":"no-useless-return","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"}