mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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,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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue