oxc-project/oxc · error

Unexpected return value in callback for {method_name:?}

Error message

Unexpected return value in callback for {method_name:?}

What it means

Lint diagnostic from eslint/array-callback-return (expect_no_return): a callback passed to an array method whose return value is ignored (e.g. forEach, every's opposite set) explicitly returns a value. The returned value goes nowhere, so the return suggests the wrong method is being used.

Source

Thrown at crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs:115

            ),
        ),
    };

    let mut diagnostic = OxcDiagnostic::warn(message).with_help(help).with_label(diagnostic_span);
    if allow_implicit {
        diagnostic = diagnostic.with_note("With `allowImplicit`, callbacks that don't explicitly return a value are considered to return `undefined`.");
    }
    if let Some((hint_span, _)) = hint {
        diagnostic = diagnostic
            .and_label(hint_span.label("This path may reach the end of the callback."))
            .and_label(array_method_span.label(format!("{method_name:?} is called here.")));
    }

    diagnostic
}

fn expect_no_return(method_name: &str, call_span: Span, return_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Unexpected return value in callback for {method_name:?}"))
        .with_help(format!(
            "{method_name:?} ignores the callback's return value. Remove the returned value (use `return;` or no `return`), or use `map`/`flatMap` if you meant to produce a new array."
        ))
        .with_labels([
            call_span.label(format!("{method_name:?} is called here.")),
            return_span.label("This returned value is ignored."),
        ])
}

fn expect_void_return(method_name: &str, call_span: Span, return_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Unexpected return value in callback for {method_name:?}"))
        .with_help("Expected the return expression to be started with `void`")
        .with_labels([
            call_span.label(format!("{method_name:?} is called here.")),
            return_span.label("Prepend `void` to the expression."),
        ])
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the return statement if the side effect is intended
  2. Switch to the appropriate method such as map, filter, or some when the return value matters
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs:115 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/2e7297e7f69cfea1. Report an issue: GitHub.