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
- 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).
- Pick the mode that matches team convention: "all" for safety, "multi-line" for compactness.
- 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
- Standardize one curly mode in the shared config so whole-file style stays consistent.
- Prefer `all` in codebases touched by many contributors — braceless bodies cause merge bugs.
- Apply fixes file-wide with the editor/oxfmt instead of one statement at a time.
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
- Expected method{method_name_str} to have this.
- Enforce default clauses in switch statements to be last
- Expected a function {style}.
- Accessor pair {getter_key} and {setter_key} should be groupe
- Expected {getter_key} to be before {setter_key}.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/cc0eefa24edfef3c.
Report an issue: GitHub.