{"record":{"id":"391313bd690c5f51","repo":"oxc-project/oxc","slug":"void-dom-element-tag-cannot-receive-childr","errorCode":null,"errorMessage":"Void DOM element <{tag:?} /> cannot receive children.","messagePattern":"Void DOM element <(.+?) /> cannot receive children\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/void_dom_elements_no_children.rs","lineNumber":21,"sourceCode":"    ast::{\n        Argument, JSXAttributeItem, JSXAttributeName, JSXElementName, ObjectPropertyKind,\n        PropertyKey,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n    utils::is_create_element_call,\n};\n\nfn void_dom_elements_no_children_diagnostic(tag: &str, span: Span) -> OxcDiagnostic {\n    // TODO: use imperative phrasing\n    OxcDiagnostic::warn(format!(\"Void DOM element <{tag:?} /> cannot receive children.\"))\n        .with_help(\"Remove this element's children or use a non-void element.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct VoidDomElementsNoChildren;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow void DOM elements (e.g. `<img />`, `<br />`) from receiving children.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// There are some HTML elements that are only self-closing (e.g. img, br, hr). These are collectively known as void DOM elements.\n    /// This rule checks that children are not passed to void DOM elements.\n    ///\n    /// ### Examples","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/void_dom_elements_no_children.rs#L3-L39","documentation":"Raised by react/void_dom_elements_no_children when children are passed to a void DOM element (`<br>`, `<img>`, `<input>`, `<hr>`, `<wbr>` etc.), either as JSX children or via a children prop/argument in createElement. At the throw site void elements cannot have children by HTML definition — the browser will ignore or relocate the content, and React warns. void_dom_elements_no_children_diagnostic fires from run() with the offending tag name when a child is detected on one of the void tags.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/void_dom_elements_no_children.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the children from the void element.","Use a non-void element if children are genuinely needed."],"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"}