mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(linter/unicorn): add fixer to no-redundant-roles (#5146)
This commit is contained in:
parent
d35c6f5dfc
commit
2fe44153ac
1 changed files with 12 additions and 6 deletions
|
|
@ -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() {
|
|||
("<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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue