Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}