oxc-project/oxc · error

Expected block statement surrounding arrow body.

Error message

Expected block statement surrounding arrow body.

What it means

Lint diagnostic from eslint/arrow-body-style in 'always' mode: an arrow function uses a concise expression body instead of a block statement, violating the configured style that all arrow bodies be brace-wrapped with an explicit return.

Source

Thrown at crates/oxc_linter/src/rules/eslint/arrow_body_style.rs:22

use oxc_ast::{
    AstKind,
    ast::{ArrowFunctionExpression, Expression, ReturnStatement, Statement},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::BinaryOperator;

use crate::{
    AstNode,
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    rule::{Rule, TupleRuleConfig},
};

fn expected_block_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Expected block statement surrounding arrow body.")
        .with_help("Surround the arrow body with braces and use a return statement.")
        .with_label(span)
}

fn unexpected_block_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected block statement surrounding arrow body.")
        .with_help("Move the returned value to be immediately after the `=>`.")
        .with_label(span)
}

fn unexpected_empty_block_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected empty block statement surrounding arrow body.")
        .with_help("Put a value of `undefined` immediately after the `=>`.")
        .with_label(span)
}

/// Diagnostic that is emitted when we don't have a specific help message to provide
fn unexpected_block_with_unknown_help_diagnostic(span: Span) -> OxcDiagnostic {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Wrap the body in braces and return the expression: (x) => { return x; }
  2. Apply the rule's autofix
  3. Change the rule option to as-needed if expression bodies are preferred
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/eslint/arrow_body_style.rs:22 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/e3266418b043ea71. Report an issue: GitHub.