Skip to content

Commit 6908bc3

Browse files
authored
feat(linter): add autofix for react/self-closing-comp (#10512)
Related to #10477
1 parent e67901b commit 6908bc3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

crates/oxc_linter/src/rules/react/self_closing_comp.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare_oxc_lint!(
6060
SelfClosingComp,
6161
react,
6262
style,
63-
pending
63+
fix
6464
);
6565

6666
impl Rule for SelfClosingComp {
@@ -121,7 +121,12 @@ impl Rule for SelfClosingComp {
121121
}
122122

123123
if self.html && is_dom_comp || self.component && !is_dom_comp {
124-
ctx.diagnostic(self_closing_comp_diagnostic(jsx_closing_elem.span));
124+
ctx.diagnostic_with_fix(self_closing_comp_diagnostic(jsx_closing_elem.span), |fixer| {
125+
fixer.replace(
126+
Span::new(jsx_el.opening_element.span.end - 1, jsx_closing_elem.span.end),
127+
" />",
128+
)
129+
});
125130
}
126131
}
127132

@@ -284,7 +289,7 @@ fn test() {
284289
),
285290
];
286291

287-
let _fix = vec![
292+
let fix = vec![
288293
(
289294
r#"var contentContainer = <div className="content"></div>;"#,
290295
r#"var contentContainer = <div className="content" />;"#,
@@ -351,5 +356,7 @@ fn test() {
351356
Some(serde_json::json!([{ "html": true }])),
352357
),
353358
];
354-
Tester::new(SelfClosingComp::NAME, SelfClosingComp::PLUGIN, pass, fail).test_and_snapshot();
359+
Tester::new(SelfClosingComp::NAME, SelfClosingComp::PLUGIN, pass, fail)
360+
.expect_fix(fix)
361+
.test_and_snapshot();
355362
}

0 commit comments

Comments
 (0)