Skip to content

Commit 13c7b1b

Browse files
committed
feat(linter/jsx-a11y): add fixer for aria-unsupported-elements (#4854)
1 parent 56f033c commit 13c7b1b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ declare_oxc_lint! {
3030
/// ```
3131
///
3232
AriaUnsupportedElements,
33-
correctness
33+
correctness,
34+
fix
3435
}
3536

3637
#[derive(Debug, Default, Clone)]
@@ -56,7 +57,10 @@ impl Rule for AriaUnsupportedElements {
5657
};
5758
let attr_name = get_jsx_attribute_name(&attr.name).to_lowercase();
5859
if INVALID_ATTRIBUTES.contains(&attr_name) {
59-
ctx.diagnostic(aria_unsupported_elements_diagnostic(attr.span, &attr_name));
60+
ctx.diagnostic_with_fix(
61+
aria_unsupported_elements_diagnostic(attr.span, &attr_name),
62+
|fixer| fixer.delete(&attr.span),
63+
);
6064
}
6165
}
6266
}
@@ -416,7 +420,16 @@ fn test() {
416420
(r#"<track aria-hidden aria-role="none" {...props} />"#, None),
417421
];
418422

423+
let fix = vec![
424+
(r"<col role {...props} />", r"<col {...props} />"),
425+
(
426+
r#"<meta aria-hidden aria-role="none" {...props} />"#,
427+
r#"<meta aria-role="none" {...props} />"#,
428+
),
429+
];
430+
419431
Tester::new(AriaUnsupportedElements::NAME, pass, fail)
420432
.with_jsx_a11y_plugin(true)
433+
.expect_fix(fix)
421434
.test_and_snapshot();
422435
}

0 commit comments

Comments
 (0)