From 88f9c47157ef8ef1c932b186412a862cd7a54951 Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Mon, 12 Aug 2024 15:32:54 -0400 Subject: [PATCH] feat(linter/jsx-a11y): add fixer for aria-unsupported-elements --- .../rules/jsx_a11y/aria_unsupported_elements.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs b/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs index 267ece6742bdd9..5e7f846e7430ce 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs @@ -30,7 +30,8 @@ declare_oxc_lint! { /// ``` /// AriaUnsupportedElements, - correctness + correctness, + fix } #[derive(Debug, Default, Clone)] @@ -56,7 +57,10 @@ impl Rule for AriaUnsupportedElements { }; let attr_name = get_jsx_attribute_name(&attr.name).to_lowercase(); if INVALID_ATTRIBUTES.contains(&attr_name) { - ctx.diagnostic(aria_unsupported_elements_diagnostic(attr.span, &attr_name)); + ctx.diagnostic_with_fix( + aria_unsupported_elements_diagnostic(attr.span, &attr_name), + |fixer| fixer.delete(&attr.span), + ); } } } @@ -416,7 +420,16 @@ fn test() { (r#""#, None), ]; + let fix = vec![ + (r"", r""), + ( + r#""#, + r#""#, + ), + ]; + Tester::new(AriaUnsupportedElements::NAME, pass, fail) .with_jsx_a11y_plugin(true) + .expect_fix(fix) .test_and_snapshot(); }