Skip to content

Commit 6f3bd01

Browse files
fix: resolve Clippy issues
1 parent edaf6d5 commit 6f3bd01

5 files changed

Lines changed: 109 additions & 112 deletions

File tree

packages/aria-hidden/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ fn correct_targets(parent: HtmlElement, targets: Vec<Element>) -> Vec<Element> {
6363
return Some(target);
6464
}
6565

66-
if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone())) {
67-
if parent.contains(Some(&corrected_target)) {
68-
return Some(corrected_target);
69-
}
66+
if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone()))
67+
&& parent.contains(Some(&corrected_target))
68+
{
69+
return Some(corrected_target);
7070
}
7171

7272
None

packages/aria-query/src/element_role_map.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ pub static ELEMENT_ROLES: LazyLock<HashMap<AriaRoleRelationConcept, Vec<AriaRole
1313
.chain(role.related_concepts.iter());
1414

1515
for relation in concepts {
16-
if relation.module == Some("HTML".into()) {
17-
if let Some(concept) = &relation.concept {
18-
let element_role_relation = element_roles.get(concept);
19-
let mut roles: Vec<AriaRoleDefinitionKey> = vec![];
20-
21-
if let Some(element_role_relation) = element_role_relation {
22-
roles.extend(element_role_relation);
23-
}
16+
if relation.module == Some("HTML".into())
17+
&& let Some(concept) = &relation.concept
18+
{
19+
let element_role_relation = element_roles.get(concept);
20+
let mut roles: Vec<AriaRoleDefinitionKey> = vec![];
21+
22+
if let Some(element_role_relation) = element_role_relation {
23+
roles.extend(element_role_relation);
24+
}
2425

25-
let mut is_unique = true;
26-
for role in &roles {
27-
if *role == *key {
28-
is_unique = false;
29-
break;
30-
}
31-
}
32-
if is_unique {
33-
roles.push(*key);
26+
let mut is_unique = true;
27+
for role in &roles {
28+
if *role == *key {
29+
is_unique = false;
30+
break;
3431
}
32+
}
33+
if is_unique {
34+
roles.push(*key);
35+
}
3536

36-
if element_role_relation.is_none() {
37-
element_roles.insert(concept.clone(), roles);
38-
}
37+
if element_role_relation.is_none() {
38+
element_roles.insert(concept.clone(), roles);
3939
}
4040
}
4141
}

packages/aria-query/src/role_element_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub static ROLE_ELEMENTS: LazyLock<HashMap<AriaRoleDefinitionKey, Vec<AriaRoleRe
1515
.chain(role.related_concepts.iter());
1616

1717
for relation in concepts {
18-
if relation.module == Some("HTML".into()) {
19-
if let Some(concept) = &relation.concept {
20-
relation_concepts.push(concept.clone());
21-
}
18+
if relation.module == Some("HTML".into())
19+
&& let Some(concept) = &relation.concept
20+
{
21+
relation_concepts.push(concept.clone());
2222
}
2323
}
2424

packages/dom-accessibility-api/src/accessible_description.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ pub fn compute_accessible_description(
3131

3232
// https://w3c.github.io/aria/#aria-description
3333
// Mentions that aria-description should only be calculated if aria-describedby didn't provide a description.
34-
if description.is_empty() {
35-
if let Some(aria_description) = root.get_attribute("aria-description") {
36-
description = aria_description;
37-
}
34+
if description.is_empty()
35+
&& let Some(aria_description) = root.get_attribute("aria-description")
36+
{
37+
description = aria_description;
3838
}
3939

4040
// https://www.w3.org/TR/html-aam-1.0/#accessible-name-and-description-computation
4141
// Says for so many elements to use the `title` that we assume all elements are considered.
42-
if description.is_empty() {
43-
if let Some(title) = root.get_attribute("title") {
44-
description = title;
45-
}
42+
if description.is_empty()
43+
&& let Some(title) = root.get_attribute("title")
44+
{
45+
description = title;
4646
}
4747

4848
description

packages/dom-accessibility-api/src/accessible_name_and_description.rs

Lines changed: 73 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -476,31 +476,29 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
476476
if let Some(name_from_alt) = use_attribute(consulted_nodes, element, "alt") {
477477
return Some(name_from_alt);
478478
}
479-
} else if element.is_instance_of::<HtmlOptGroupElement>() {
480-
if let Some(name_from_label) = use_attribute(consulted_nodes, element, "label") {
481-
return Some(name_from_label);
482-
}
479+
} else if element.is_instance_of::<HtmlOptGroupElement>()
480+
&& let Some(name_from_label) = use_attribute(consulted_nodes, element, "label")
481+
{
482+
return Some(name_from_label);
483483
}
484484

485-
if let Some(input_element) = element.dyn_ref::<HtmlInputElement>() {
486-
if input_element.type_() == "button"
485+
if let Some(input_element) = element.dyn_ref::<HtmlInputElement>()
486+
&& (input_element.type_() == "button"
487487
|| input_element.type_() == "submit"
488-
|| input_element.type_() == "reset"
489-
{
490-
// 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
491-
if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value")
492-
{
493-
return Some(name_from_value);
494-
}
488+
|| input_element.type_() == "reset")
489+
{
490+
// 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
491+
if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value") {
492+
return Some(name_from_value);
493+
}
495494

496-
// TODO: l10n
497-
if input_element.type_() == "submit" {
498-
return Some("Submit".into());
499-
}
500-
// TODO: l10n
501-
if input_element.type_() == "reset" {
502-
return Some("Reset".into());
503-
}
495+
// TODO: l10n
496+
if input_element.type_() == "submit" {
497+
return Some("Submit".into());
498+
}
499+
// TODO: l10n
500+
if input_element.type_() == "reset" {
501+
return Some("Reset".into());
504502
}
505503
}
506504

@@ -535,21 +533,21 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
535533
// https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation
536534
// TODO: WPT test consider label elements but html-aam does not mention them.
537535
// We follow existing implementations over spec.
538-
if let Some(input_element) = node.dyn_ref::<HtmlInputElement>() {
539-
if input_element.type_() == "image" {
540-
let name_for_alt = use_attribute(consulted_nodes, input_element, "alt");
541-
if let Some(name_for_alt) = name_for_alt {
542-
return Some(name_for_alt);
543-
}
544-
545-
let name_for_title = use_attribute(consulted_nodes, input_element, "title");
546-
if let Some(name_for_alt) = name_for_title {
547-
return Some(name_for_alt);
548-
}
536+
if let Some(input_element) = node.dyn_ref::<HtmlInputElement>()
537+
&& input_element.type_() == "image"
538+
{
539+
let name_for_alt = use_attribute(consulted_nodes, input_element, "alt");
540+
if let Some(name_for_alt) = name_for_alt {
541+
return Some(name_for_alt);
542+
}
549543

550-
// TODO: l10n
551-
return Some("Submit Query".into());
544+
let name_for_title = use_attribute(consulted_nodes, input_element, "title");
545+
if let Some(name_for_alt) = name_for_title {
546+
return Some(name_for_alt);
552547
}
548+
549+
// TODO: l10n
550+
return Some("Submit Query".into());
553551
}
554552

555553
if has_any_concrete_roles(node, vec!["button"]) {
@@ -595,42 +593,41 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
595593
}
596594

597595
// 2B
598-
if let Some(current) = current.dyn_ref::<Element>() {
599-
if let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby") {
600-
// TODO: Do we generally need to block query IdRefs of attributes we have already consulted?
601-
let label_elements = if !consulted_nodes.contains(&label_attribute_node) {
602-
query_id_refs(current, "aria-labelledby")
603-
} else {
604-
vec![]
605-
};
606-
607-
if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty()
608-
{
609-
consulted_nodes.push(label_attribute_node.unchecked_into::<Node>());
610-
611-
return label_elements
612-
.into_iter()
613-
.map(move |element| {
614-
// TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative.
615-
inner_compute_text_alternative(
616-
compute,
617-
hidden,
618-
uncached_get_computed_style.clone(),
619-
get_computed_style.clone(),
620-
consulted_nodes,
621-
&element,
622-
ComputeTextAlternativeContext {
623-
is_embedded_in_label: context.is_embedded_in_label,
624-
is_referenced: true,
625-
// This isn't recursion as specified, otherwise we would skip `aria-label` in
626-
// <input id="myself" aria-label="foo" aria-labelledby="myself" />
627-
recursion: false,
628-
},
629-
)
630-
})
631-
.collect::<Vec<_>>()
632-
.join(" ");
633-
}
596+
if let Some(current) = current.dyn_ref::<Element>()
597+
&& let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby")
598+
{
599+
// TODO: Do we generally need to block query IdRefs of attributes we have already consulted?
600+
let label_elements = if !consulted_nodes.contains(&label_attribute_node) {
601+
query_id_refs(current, "aria-labelledby")
602+
} else {
603+
vec![]
604+
};
605+
606+
if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty() {
607+
consulted_nodes.push(label_attribute_node.unchecked_into::<Node>());
608+
609+
return label_elements
610+
.into_iter()
611+
.map(move |element| {
612+
// TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative.
613+
inner_compute_text_alternative(
614+
compute,
615+
hidden,
616+
uncached_get_computed_style.clone(),
617+
get_computed_style.clone(),
618+
consulted_nodes,
619+
&element,
620+
ComputeTextAlternativeContext {
621+
is_embedded_in_label: context.is_embedded_in_label,
622+
is_referenced: true,
623+
// This isn't recursion as specified, otherwise we would skip `aria-label` in
624+
// <input id="myself" aria-label="foo" aria-labelledby="myself" />
625+
recursion: false,
626+
},
627+
)
628+
})
629+
.collect::<Vec<_>>()
630+
.join(" ");
634631
}
635632
}
636633

@@ -651,18 +648,18 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
651648
}
652649

653650
// 2D
654-
if !is_marked_presentational(current) {
655-
if let Some(element_text_alternative) = compute_element_text_alternative(
651+
if !is_marked_presentational(current)
652+
&& let Some(element_text_alternative) = compute_element_text_alternative(
656653
compute,
657654
hidden,
658655
uncached_get_computed_style.clone(),
659656
get_computed_style.clone(),
660657
consulted_nodes,
661658
current,
662-
) {
663-
consulted_nodes.push(current.clone());
664-
return element_text_alternative;
665-
}
659+
)
660+
{
661+
consulted_nodes.push(current.clone());
662+
return element_text_alternative;
666663
}
667664
}
668665

0 commit comments

Comments
 (0)