oxc-project/oxc · error · OxcDiagnostic
Unnecessary closing tag
Error message
Unnecessary closing tag
What it means
Raised by react/self_closing_comp when a JSX element with no children is written with explicit open and close tags (e.g. `<Component></Component>`) rather than self-closing. At the throw site the closing tag is pure noise — the two forms are semantically identical — and the project enforces the terser self-closing form. self_closing_comp_diagnostic fires from run() for elements whose children list is empty, pointing at the closing tag span.
Source
Thrown at crates/oxc_linter/src/rules/react/self_closing_comp.rs:19
use oxc_ast::{
AstKind,
ast::{JSXChild, JSXElementName},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
context::{ContextHost, LintContext},
globals::HTML_TAG,
rule::{DefaultRuleConfig, Rule},
};
fn self_closing_comp_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unnecessary closing tag")
.with_help("Make the component self closing")
.with_label(span)
}
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct SelfClosingComp {
/// Whether to enforce self-closing for custom components.
component: bool,
/// Whether to enforce self-closing for native HTML elements.
html: bool,
}
impl Default for SelfClosingComp {
fn default() -> Self {
Self { component: true, html: true }
}
}View on GitHub (pinned to e1e7af627c)
Solutions
- Use the self-closing form: <div /> instead of <div></div>.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/self_closing_comp.rs:19 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/7e281132fc84bf6d.
Report an issue: GitHub.