From 2fe44153ac019e23316ebc2fe7f78c1b7f648aaa Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 23 Aug 2024 22:38:24 +0100 Subject: [PATCH] feat(linter/unicorn): add fixer to `no-redundant-roles` (#5146) --- .../src/rules/jsx_a11y/no_redundant_roles.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs b/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs index 481220df075ac..8a03867f0f315 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs @@ -44,11 +44,11 @@ declare_oxc_lint!( /// ``` NoRedundantRoles, correctness, - pending + fix ); static DEFAULT_ROLE_EXCEPTIONS: phf::Map<&'static str, &'static str> = phf_map! { - "nav" =>"navigation", + "nav" => "navigation", "button" => "button", "body" => "document", }; @@ -69,9 +69,10 @@ impl Rule for NoRedundantRoles { for role in &roles { let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component); if exceptions.map_or(false, |set| set.contains(role)) { - ctx.diagnostic(no_redundant_roles_diagnostic( - attr.span, &component, role, - )); + ctx.diagnostic_with_fix( + no_redundant_roles_diagnostic(attr.span, &component, role), + |fixer| fixer.delete_range(attr.span), + ); } } } @@ -109,5 +110,10 @@ fn test() { ("