{"record":{"id":"87eb74850e243143","repo":"oxc-project/oxc","slug":"shorthand-form-for-react-fragments-is-preferred","errorCode":null,"errorMessage":"Shorthand form for React fragments is preferred.","messagePattern":"Shorthand form for React fragments is preferred\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/jsx_fragments.rs","lineNumber":27,"sourceCode":"use crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_jsx_fragment,\n};\n\nfn jsx_fragments_diagnostic(span: Span, mode: FragmentMode) -> OxcDiagnostic {\n    let msg = if mode == FragmentMode::Element {\n        \"Standard form for React fragments is preferred.\"\n    } else {\n        \"Shorthand form for React fragments is preferred.\"\n    };\n    let help = if mode == FragmentMode::Element {\n        \"Use `<React.Fragment></React.Fragment>` instead of `<></>`.\"\n    } else {\n        \"Use `<></>` instead of `<React.Fragment></React.Fragment>`.\"\n    };\n    OxcDiagnostic::warn(msg).with_help(help).with_label(span)\n}\n\n// Generally we should prefer the string-only syntax for compatibility with the original ESLint rule,\n// but we originally implemented the rule with only the object syntax, so we support both now.\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(untagged)]\npub enum JsxFragments {\n    Mode(FragmentMode),\n    Object { mode: FragmentMode },\n}\n\nimpl Default for JsxFragments {\n    fn default() -> Self {\n        JsxFragments::Mode(FragmentMode::Syntax)\n    }\n}\n\nimpl JsxFragments {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_fragments.rs#L9-L45","documentation":"Raised by react/jsx_fragments when the rule is in its default shorthand-preferring mode and an explicit `<React.Fragment>...</React.Fragment>` element is found (without a key, per config). At the throw site the verbose element form deviates from the enforced `<></>` idiom that the project adopted for brevity. jsx_fragments_diagnostic picks this message branch for the shorthand mode and is emitted from run() while traversing JSX elements named Fragment.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/jsx_fragments.rs:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace <React.Fragment></React.Fragment> with <></> (keeping keys via the keyed form when needed).","Switch the rule mode to 'element' if the explicit form is preferred."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}