oxc-project/oxc · warning · OxcDiagnostic

{prefix} {{ after '{keyword}'{condition_if_needed}.

Error message

{prefix} {{ after '{keyword}'{condition_if_needed}.

What it means

Oxlint's port of the ESLint rule curly. It enforces a chosen brace policy for the bodies of `if`, `else`, `for`, `while`, and `do`. The message is assembled in curly_diagnostic (crates/oxc_linter/src/rules/eslint/curly.rs:13): the prefix is Expected/Unexpected depending on the configured direction, and the suffix " condition" is appended only when the keyword is if, while, or for — so the rendered text is e.g. "Expected `{` after 'if' condition." or "Unexpected `{` after 'else'.". Modes come from the kebab-case CurlyType enum: `all` (default), `multi`, `multi-line`, `multi-or-nest`.

Source

Thrown at crates/oxc_linter/src/rules/eslint/curly.rs:18

use crate::fixer::{RuleFix, RuleFixer};
use crate::rule::TupleRuleConfig;
use crate::{AstNode, context::LintContext, rule::Rule};
use oxc_ast::{AstKind, ast::IfStatement, ast::Statement};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

fn curly_diagnostic(span: Span, keyword: &str, expected: bool) -> OxcDiagnostic {
    let condition_if_needed =
        matches!(keyword, "if" | "while" | "for").then_some(" condition").unwrap_or("");
    let prefix = if expected { "Expected" } else { "Unexpected" };
    let message = format!("{prefix} {{ after '{keyword}'{condition_if_needed}.");

    OxcDiagnostic::warn(message).with_label(span)
}

/// The enforcement type for the curly rule.
#[derive(Debug, Default, Clone, PartialEq, Eq, JsonSchema, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum CurlyType {
    /// Require braces in all cases (default)
    #[default]
    All,
    /// Require braces only when there are multiple statements in the block
    Multi,
    /// Require braces when the block spans multiple lines
    MultiLine,
    /// Require braces when the block is nested or spans multiple lines
    MultiOrNest,
}

/// Configuration for the curly rule, specified as an array of one or two elements.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add braces to the flagged body (or remove them when running multi-line/multi-or-nest and the body is a single same-line statement).
  2. Pick the mode that matches team convention: "all" for safety, "multi-line" for compactness.
  3. Fix the whole file with the editor or oxfmt rather than statement by statement.

Example fix

// before (mode: all)
if (done) return;

// after
if (done) {
  return;
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — choose the policy that matches the codebase
{
  "rules": {
    "curly": ["warn", "all"]
  }
}

Prevention

When it happens

Trigger: Under `all`: any braceless body such as `if (x) return;`. Under `multi`/`multi-line`/`multi-or-nest`: multi-statement or multi-line bodies left without braces, or (multi-or-nest) a nested statement that does not sit on the same line as its keyword.

Common situations: Mixed-style files after merges or contributions; enabling `all` on code written brace-free for compactness; churn between hand-written style and formatter output.

Related errors


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