mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
feat(linter): add fixer for jsx_ally/no_aria_hidden_on_focusable (#4772)
part of #4179
This commit is contained in:
parent
c509a21a1f
commit
abd83fa998
1 changed files with 16 additions and 3 deletions
|
|
@ -38,7 +38,8 @@ declare_oxc_lint!(
|
|||
/// <div aria-hidden="true" />
|
||||
/// ```
|
||||
NoAriaHiddenOnFocusable,
|
||||
correctness
|
||||
correctness,
|
||||
fix
|
||||
);
|
||||
|
||||
impl Rule for NoAriaHiddenOnFocusable {
|
||||
|
|
@ -49,7 +50,10 @@ impl Rule for NoAriaHiddenOnFocusable {
|
|||
if let Some(aria_hidden_prop) = has_jsx_prop_ignore_case(jsx_el, "aria-hidden") {
|
||||
if is_aria_hidden_true(aria_hidden_prop) && is_focusable(ctx, jsx_el) {
|
||||
if let JSXAttributeItem::Attribute(boxed_attr) = aria_hidden_prop {
|
||||
ctx.diagnostic(no_aria_hidden_on_focusable_diagnostic(boxed_attr.span));
|
||||
ctx.diagnostic_with_fix(
|
||||
no_aria_hidden_on_focusable_diagnostic(boxed_attr.span),
|
||||
|fixer| fixer.delete(&boxed_attr.span),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,5 +131,14 @@ fn test() {
|
|||
r#"<p tabIndex="0" aria-hidden="true">text</p>;"#,
|
||||
];
|
||||
|
||||
Tester::new(NoAriaHiddenOnFocusable::NAME, pass, fail).test_and_snapshot();
|
||||
let fix = vec![
|
||||
(r#"<div aria-hidden="true" tabIndex="0" />;"#, r#"<div tabIndex="0" />;"#),
|
||||
(r#"<input aria-hidden="true" />;"#, "<input />;"),
|
||||
(r#"<a href="/" aria-hidden="true" />"#, r#"<a href="/" />"#),
|
||||
(r#"<button aria-hidden="true" />"#, "<button />"),
|
||||
(r#"<textarea aria-hidden="true" />"#, "<textarea />"),
|
||||
(r#"<p tabIndex="0" aria-hidden="true">text</p>;"#, r#"<p tabIndex="0" >text</p>;"#),
|
||||
];
|
||||
|
||||
Tester::new(NoAriaHiddenOnFocusable::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue