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