From 6f3bd010f31388cf32f231a7be2762527bc2e4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABlle=20Huisman?= Date: Mon, 11 Aug 2025 13:30:10 +0200 Subject: [PATCH] fix: resolve Clippy issues --- packages/aria-hidden/src/lib.rs | 8 +- packages/aria-query/src/element_role_map.rs | 40 ++--- packages/aria-query/src/role_element_map.rs | 8 +- .../src/accessible_description.rs | 16 +- .../src/accessible_name_and_description.rs | 149 +++++++++--------- 5 files changed, 109 insertions(+), 112 deletions(-) diff --git a/packages/aria-hidden/src/lib.rs b/packages/aria-hidden/src/lib.rs index 3154619..b9be3e9 100644 --- a/packages/aria-hidden/src/lib.rs +++ b/packages/aria-hidden/src/lib.rs @@ -63,10 +63,10 @@ fn correct_targets(parent: HtmlElement, targets: Vec) -> Vec { return Some(target); } - if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone())) { - if parent.contains(Some(&corrected_target)) { - return Some(corrected_target); - } + if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone())) + && parent.contains(Some(&corrected_target)) + { + return Some(corrected_target); } None diff --git a/packages/aria-query/src/element_role_map.rs b/packages/aria-query/src/element_role_map.rs index 8e9d9f5..3919f49 100644 --- a/packages/aria-query/src/element_role_map.rs +++ b/packages/aria-query/src/element_role_map.rs @@ -13,29 +13,29 @@ pub static ELEMENT_ROLES: LazyLock = vec![]; - - if let Some(element_role_relation) = element_role_relation { - roles.extend(element_role_relation); - } + if relation.module == Some("HTML".into()) + && let Some(concept) = &relation.concept + { + let element_role_relation = element_roles.get(concept); + let mut roles: Vec = vec![]; + + if let Some(element_role_relation) = element_role_relation { + roles.extend(element_role_relation); + } - let mut is_unique = true; - for role in &roles { - if *role == *key { - is_unique = false; - break; - } - } - if is_unique { - roles.push(*key); + let mut is_unique = true; + for role in &roles { + if *role == *key { + is_unique = false; + break; } + } + if is_unique { + roles.push(*key); + } - if element_role_relation.is_none() { - element_roles.insert(concept.clone(), roles); - } + if element_role_relation.is_none() { + element_roles.insert(concept.clone(), roles); } } } diff --git a/packages/aria-query/src/role_element_map.rs b/packages/aria-query/src/role_element_map.rs index 9d672f4..8a102cb 100644 --- a/packages/aria-query/src/role_element_map.rs +++ b/packages/aria-query/src/role_element_map.rs @@ -15,10 +15,10 @@ pub static ROLE_ELEMENTS: LazyLock() { - if let Some(name_from_label) = use_attribute(consulted_nodes, element, "label") { - return Some(name_from_label); - } + } else if element.is_instance_of::() + && let Some(name_from_label) = use_attribute(consulted_nodes, element, "label") + { + return Some(name_from_label); } - if let Some(input_element) = element.dyn_ref::() { - if input_element.type_() == "button" + if let Some(input_element) = element.dyn_ref::() + && (input_element.type_() == "button" || input_element.type_() == "submit" - || input_element.type_() == "reset" - { - // https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation - if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value") - { - return Some(name_from_value); - } + || input_element.type_() == "reset") + { + // https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation + if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value") { + return Some(name_from_value); + } - // TODO: l10n - if input_element.type_() == "submit" { - return Some("Submit".into()); - } - // TODO: l10n - if input_element.type_() == "reset" { - return Some("Reset".into()); - } + // TODO: l10n + if input_element.type_() == "submit" { + return Some("Submit".into()); + } + // TODO: l10n + if input_element.type_() == "reset" { + return Some("Reset".into()); } } @@ -535,21 +533,21 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO // https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation // TODO: WPT test consider label elements but html-aam does not mention them. // We follow existing implementations over spec. - if let Some(input_element) = node.dyn_ref::() { - if input_element.type_() == "image" { - let name_for_alt = use_attribute(consulted_nodes, input_element, "alt"); - if let Some(name_for_alt) = name_for_alt { - return Some(name_for_alt); - } - - let name_for_title = use_attribute(consulted_nodes, input_element, "title"); - if let Some(name_for_alt) = name_for_title { - return Some(name_for_alt); - } + if let Some(input_element) = node.dyn_ref::() + && input_element.type_() == "image" + { + let name_for_alt = use_attribute(consulted_nodes, input_element, "alt"); + if let Some(name_for_alt) = name_for_alt { + return Some(name_for_alt); + } - // TODO: l10n - return Some("Submit Query".into()); + let name_for_title = use_attribute(consulted_nodes, input_element, "title"); + if let Some(name_for_alt) = name_for_title { + return Some(name_for_alt); } + + // TODO: l10n + return Some("Submit Query".into()); } if has_any_concrete_roles(node, vec!["button"]) { @@ -595,42 +593,41 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO } // 2B - if let Some(current) = current.dyn_ref::() { - if let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby") { - // TODO: Do we generally need to block query IdRefs of attributes we have already consulted? - let label_elements = if !consulted_nodes.contains(&label_attribute_node) { - query_id_refs(current, "aria-labelledby") - } else { - vec![] - }; - - if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty() - { - consulted_nodes.push(label_attribute_node.unchecked_into::()); - - return label_elements - .into_iter() - .map(move |element| { - // TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative. - inner_compute_text_alternative( - compute, - hidden, - uncached_get_computed_style.clone(), - get_computed_style.clone(), - consulted_nodes, - &element, - ComputeTextAlternativeContext { - is_embedded_in_label: context.is_embedded_in_label, - is_referenced: true, - // This isn't recursion as specified, otherwise we would skip `aria-label` in - // - recursion: false, - }, - ) - }) - .collect::>() - .join(" "); - } + if let Some(current) = current.dyn_ref::() + && let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby") + { + // TODO: Do we generally need to block query IdRefs of attributes we have already consulted? + let label_elements = if !consulted_nodes.contains(&label_attribute_node) { + query_id_refs(current, "aria-labelledby") + } else { + vec![] + }; + + if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty() { + consulted_nodes.push(label_attribute_node.unchecked_into::()); + + return label_elements + .into_iter() + .map(move |element| { + // TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative. + inner_compute_text_alternative( + compute, + hidden, + uncached_get_computed_style.clone(), + get_computed_style.clone(), + consulted_nodes, + &element, + ComputeTextAlternativeContext { + is_embedded_in_label: context.is_embedded_in_label, + is_referenced: true, + // This isn't recursion as specified, otherwise we would skip `aria-label` in + // + recursion: false, + }, + ) + }) + .collect::>() + .join(" "); } } @@ -651,18 +648,18 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO } // 2D - if !is_marked_presentational(current) { - if let Some(element_text_alternative) = compute_element_text_alternative( + if !is_marked_presentational(current) + && let Some(element_text_alternative) = compute_element_text_alternative( compute, hidden, uncached_get_computed_style.clone(), get_computed_style.clone(), consulted_nodes, current, - ) { - consulted_nodes.push(current.clone()); - return element_text_alternative; - } + ) + { + consulted_nodes.push(current.clone()); + return element_text_alternative; } }