Skip to content

Commit

Permalink
feat(linter): add fixer for jsx_ally/no_aria_hidden_on_focusable (#4772)
Browse files Browse the repository at this point in the history
part of #4179
  • Loading branch information
heygsc authored Aug 9, 2024
1 parent c509a21 commit abd83fa
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ declare_oxc_lint!(
/// <div aria-hidden="true" />
/// ```
NoAriaHiddenOnFocusable,
correctness
correctness,
fix
);

impl Rule for NoAriaHiddenOnFocusable {
Expand All @@ -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),
);
}
}
}
Expand Down Expand Up @@ -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();
}

0 comments on commit abd83fa

Please sign in to comment.