mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(linter/jsx-a11y): add fixer for aria-unsupported-elements (#4854)
This commit is contained in:
parent
56f033c556
commit
13c7b1b9d2
1 changed files with 15 additions and 2 deletions
|
|
@ -30,7 +30,8 @@ declare_oxc_lint! {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
AriaUnsupportedElements,
|
AriaUnsupportedElements,
|
||||||
correctness
|
correctness,
|
||||||
|
fix
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
|
|
@ -56,7 +57,10 @@ impl Rule for AriaUnsupportedElements {
|
||||||
};
|
};
|
||||||
let attr_name = get_jsx_attribute_name(&attr.name).to_lowercase();
|
let attr_name = get_jsx_attribute_name(&attr.name).to_lowercase();
|
||||||
if INVALID_ATTRIBUTES.contains(&attr_name) {
|
if INVALID_ATTRIBUTES.contains(&attr_name) {
|
||||||
ctx.diagnostic(aria_unsupported_elements_diagnostic(attr.span, &attr_name));
|
ctx.diagnostic_with_fix(
|
||||||
|
aria_unsupported_elements_diagnostic(attr.span, &attr_name),
|
||||||
|
|fixer| fixer.delete(&attr.span),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -416,7 +420,16 @@ fn test() {
|
||||||
(r#"<track aria-hidden aria-role="none" {...props} />"#, None),
|
(r#"<track aria-hidden aria-role="none" {...props} />"#, None),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let fix = vec![
|
||||||
|
(r"<col role {...props} />", r"<col {...props} />"),
|
||||||
|
(
|
||||||
|
r#"<meta aria-hidden aria-role="none" {...props} />"#,
|
||||||
|
r#"<meta aria-role="none" {...props} />"#,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
Tester::new(AriaUnsupportedElements::NAME, pass, fail)
|
Tester::new(AriaUnsupportedElements::NAME, pass, fail)
|
||||||
.with_jsx_a11y_plugin(true)
|
.with_jsx_a11y_plugin(true)
|
||||||
|
.expect_fix(fix)
|
||||||
.test_and_snapshot();
|
.test_and_snapshot();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue