mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(linter): Add fixer for jsx-a11y/no-access-key rule (#6781)
This commit is contained in:
parent
442975408b
commit
a73c5af0f5
1 changed files with 24 additions and 4 deletions
|
|
@ -37,7 +37,8 @@ declare_oxc_lint!(
|
|||
/// <div />
|
||||
/// ```
|
||||
NoAccessKey,
|
||||
correctness
|
||||
correctness,
|
||||
suggestion,
|
||||
);
|
||||
|
||||
impl Rule for NoAccessKey {
|
||||
|
|
@ -50,12 +51,17 @@ impl Rule for NoAccessKey {
|
|||
{
|
||||
match attr.value.as_ref() {
|
||||
Some(JSXAttributeValue::StringLiteral(_)) => {
|
||||
ctx.diagnostic(no_access_key_diagnostic(attr.span));
|
||||
ctx.diagnostic_with_suggestion(no_access_key_diagnostic(attr.span), |fixer| {
|
||||
fixer.delete(&attr.span)
|
||||
});
|
||||
}
|
||||
Some(JSXAttributeValue::ExpressionContainer(container)) => {
|
||||
if container.expression.is_expression() && !container.expression.is_undefined()
|
||||
{
|
||||
ctx.diagnostic(no_access_key_diagnostic(attr.span));
|
||||
ctx.diagnostic_with_suggestion(
|
||||
no_access_key_diagnostic(attr.span),
|
||||
|fixer| fixer.delete(&attr.span),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -84,5 +90,19 @@ fn test() {
|
|||
r"<div accessKey={`${undefined}${undefined}`} />",
|
||||
];
|
||||
|
||||
Tester::new(NoAccessKey::NAME, pass, fail).test_and_snapshot();
|
||||
let fix = vec![
|
||||
(r#"<div accesskey="h" />"#, r"<div />"),
|
||||
(r#"<div accessKey="h" />"#, r"<div />"),
|
||||
(r#"<div accessKey="h" {...props} />"#, r"<div {...props} />"),
|
||||
(r#"<div acCesSKeY="y" />"#, r"<div />"),
|
||||
(r#"<div accessKey={"y"} />"#, r"<div />"),
|
||||
(r"<div accessKey={`${y}`} />", r"<div />"),
|
||||
(r"<div accessKey={`${undefined}y${undefined}`} />", r"<div />"),
|
||||
(r"<div accessKey={`This is ${bad}`} />", r"<div />"),
|
||||
(r"<div accessKey={accessKey} />", r"<div />"),
|
||||
(r"<div accessKey={`${undefined}`} />", r"<div />"),
|
||||
(r"<div accessKey={`${undefined}${undefined}`} />", r"<div />"),
|
||||
];
|
||||
|
||||
Tester::new(NoAccessKey::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue