fix(linter): false positive in jsx-a11y/label-has-associated-control (#7881)

closes #7849

This is essentially because `get_element_type` does not support
recognizing tag names like `<a.b />`. I'm unsure whether we should
support it.
This commit is contained in:
dalaoshu 2024-12-14 21:22:31 +08:00 committed by GitHub
parent fb897f6c3a
commit 32935e6875
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -206,10 +206,12 @@ impl Rule for LabelHasAssociatedControl {
return;
};
if let Some(element_type) = get_element_type(ctx, &element.opening_element) {
if self.label_components.binary_search(&element_type.into()).is_err() {
return;
}
let Some(element_type) = get_element_type(ctx, &element.opening_element) else {
return;
};
if self.label_components.binary_search(&element_type.into()).is_err() {
return;
}
let has_html_for = has_jsx_prop(&element.opening_element, "htmlFor").is_some();
@ -915,6 +917,8 @@ fn test() {
}])),
None,
),
// Issue: <https://github.com/oxc-project/oxc/issues/7849>
("<FilesContext.Provider value={{ addAlert, cwdInfo }} />", None, None),
];
let fail = vec![