Skip to content

Commit

Permalink
feat(linter/unicorn): add fixer to no-redundant-roles (#5146)
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Aug 23, 2024
1 parent d35c6f5 commit 2fe4415
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand All @@ -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),
);
}
}
}
Expand Down Expand Up @@ -109,5 +110,10 @@ fn test() {
("<Button role='button' />", None, Some(settings()), None),
];

Tester::new(NoRedundantRoles::NAME, pass, fail).test_and_snapshot();
let fix = vec![
("<button role='button' />", "<button />"),
("<body role='document' />", "<body />"),
];

Tester::new(NoRedundantRoles::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}

0 comments on commit 2fe4415

Please sign in to comment.