-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDuplicateContentDescriptionRule.kt
More file actions
32 lines (28 loc) · 1.36 KB
/
Copy pathDuplicateContentDescriptionRule.kt
File metadata and controls
32 lines (28 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.composea11yscanner.rules
import com.composea11yscanner.core.model.A11yIssue
import com.composea11yscanner.core.model.A11yNode
import com.composea11yscanner.core.model.A11ySeverity
import com.composea11yscanner.core.rule.BaseScanRule
class DuplicateContentDescriptionRule : BaseScanRule() {
override val ruleId = "duplicate-content-description"
override val ruleName = "Duplicate Content Description"
override val severity = A11ySeverity.Warning
override val wcagReference = "WCAG 2.4.6 Headings and Labels (Level AA)"
override fun evaluateAll(nodes: List<A11yNode>): List<A11yIssue> =
nodes
.filter { !it.contentDescription.isNullOrBlank() && !it.isMergedDescendant }
.groupBy { it.depth to it.contentDescription }
.filter { (_, group) -> group.size > 1 }
.flatMap { (key, group) ->
val text = key.second
group.map { node ->
issue(
node = node,
message = "Two elements share the same content description: '$text'. " +
"Screen readers may confuse users.",
howToFix = "Give each element a unique content description that " +
"identifies its specific action or content.",
)
}
}
}