feat(linter/unicorn): add fixer to no-redundant-roles (#5146)

This commit is contained in:
Cameron 2024-08-23 22:38:24 +01:00 committed by GitHub
parent d35c6f5dfc
commit 2fe44153ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}