{"record":{"id":"cc0eefa24edfef3c","repo":"oxc-project/oxc","slug":"prefix-after-keyword-condition-if-needed","errorCode":null,"errorMessage":"{prefix} {{ after '{keyword}'{condition_if_needed}.","messagePattern":"\\{prefix\\} \\{\\{ after '\\{keyword\\}'\\{condition_if_needed\\}\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/curly.rs","lineNumber":18,"sourceCode":"use crate::fixer::{RuleFix, RuleFixer};\nuse crate::rule::TupleRuleConfig;\nuse crate::{AstNode, context::LintContext, rule::Rule};\nuse oxc_ast::{AstKind, ast::IfStatement, ast::Statement};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse serde_json::Value;\n\nfn curly_diagnostic(span: Span, keyword: &str, expected: bool) -> OxcDiagnostic {\n    let condition_if_needed =\n        matches!(keyword, \"if\" | \"while\" | \"for\").then_some(\" condition\").unwrap_or(\"\");\n    let prefix = if expected { \"Expected\" } else { \"Unexpected\" };\n    let message = format!(\"{prefix} {{ after '{keyword}'{condition_if_needed}.\");\n\n    OxcDiagnostic::warn(message).with_label(span)\n}\n\n/// The enforcement type for the curly rule.\n#[derive(Debug, Default, Clone, PartialEq, Eq, JsonSchema, Deserialize, Serialize)]\n#[serde(rename_all = \"kebab-case\")]\npub enum CurlyType {\n    /// Require braces in all cases (default)\n    #[default]\n    All,\n    /// Require braces only when there are multiple statements in the block\n    Multi,\n    /// Require braces when the block spans multiple lines\n    MultiLine,\n    /// Require braces when the block is nested or spans multiple lines\n    MultiOrNest,\n}\n\n/// Configuration for the curly rule, specified as an array of one or two elements.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/curly.rs#L1-L36","documentation":"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`.","triggerScenarios":"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.","commonSituations":"Mixed-style files after merges or contributions; enabling `all` on code written brace-free for compactness; churn between hand-written style and formatter output.","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."],"exampleFix":"// before (mode: all)\nif (done) return;\n\n// after\nif (done) {\n  return;\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — choose the policy that matches the codebase\n{\n  \"rules\": {\n    \"curly\": [\"warn\", \"all\"]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["eslint","oxlint","curly","braces","style"],"backgroundTag":"missing-braces-control-flow","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}