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,7 +44,7 @@ declare_oxc_lint!(
/// ``` /// ```
NoRedundantRoles, NoRedundantRoles,
correctness, correctness,
pending fix
); );
static DEFAULT_ROLE_EXCEPTIONS: phf::Map<&'static str, &'static str> = phf_map! { static DEFAULT_ROLE_EXCEPTIONS: phf::Map<&'static str, &'static str> = phf_map! {
@ -69,9 +69,10 @@ impl Rule for NoRedundantRoles {
for role in &roles { for role in &roles {
let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component); let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component);
if exceptions.map_or(false, |set| set.contains(role)) { if exceptions.map_or(false, |set| set.contains(role)) {
ctx.diagnostic(no_redundant_roles_diagnostic( ctx.diagnostic_with_fix(
attr.span, &component, role, 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), ("<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();
} }