Skip to content

Commit

Permalink
chore(rules): add label for missing id handling [H44]
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 19, 2023
1 parent a8402fb commit 37ea0d6
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ let audit = accessibility_rs::audit(&AuditConfig::new(&html, &css, false, "en"))
1. Incredibly fast nanosecond audits.
1. i18n support.

### Contributing

To help improve the rules the following needs to be done:

1. Add the [rule](./RULES.md) to the tracking list - you can use the [standards list and mappings here](https://squizlabs.github.io/HTML_CodeSniffer/Standards/WCAG2/) for help.
1. Add the logic of handling the rule to [wcag_rule_map](./accessibility-rs/src/engine/rules/wcag_rule_map.rs) and the [techniques](./accessibility-rs/src/engine/rules/techniques.rs).
1. Add [unit](./accessibility-rs/tests/unit/mod.rs) test.

## Examples

1. [Wasm](https://webassembly.org/) example view [kayle_innate](https://github.com/a11ywatch/kayle/blob/main/kayle_innate/kayle_innate/src/lib.rs#L35).
1. Example integrating with a [headless browser](https://github.com/a11ywatch/kayle/blob/main/kayle/tests/innate.ts#L14).

## Benchmarks

```sh
Expand All @@ -52,6 +39,19 @@ audit-speed/core/audit: large html (4k iterations)
time: [1.1475 ms 1.1507 ms 1.1531 ms]
```

## Examples

1. [Wasm](https://webassembly.org/) example view [kayle_innate](https://github.com/a11ywatch/kayle/blob/main/kayle_innate/kayle_innate/src/lib.rs#L35).
1. Example integrating with a [headless browser](https://github.com/a11ywatch/kayle/blob/main/kayle/tests/innate.ts#L14).

### Contributing

To help improve the rules the following needs to be done:

1. Add the [rule](./RULES.md) to the tracking list - you can use the [standards list and mappings here](https://squizlabs.github.io/HTML_CodeSniffer/Standards/WCAG2/) for help.
1. Add the logic of handling the rule to [wcag_rule_map](./accessibility-rs/src/engine/rules/wcag_rule_map.rs) and the [techniques](./accessibility-rs/src/engine/rules/techniques.rs).
1. Add [unit](./accessibility-rs/tests/unit/mod.rs) test.

### License

This project is licensed under either of
Expand Down
3 changes: 2 additions & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ List of [WCAG2.1 techniques](https://www.w3.org/TR/WCAG21/) and whether or not w
| [H36](https://www.w3.org/TR/WCAG20-TECHS/H36.html) | missing form img alt | A-AAA | error | ||
| [H37](https://www.w3.org/TR/WCAG20-TECHS/H37.html) | missing img alt | A-AAA | error | ||
| [H42](https://www.w3.org/TR/WCAG20-TECHS/H42.html) | heading found with no content | A-AAA | error | ||
| [H44](https://www.w3.org/TR/WCAG20-TECHS/H44.html) | label's "for" attribute contains an ID that does not exist | A-AAA | error | ||
| [H53](https://www.w3.org/TR/WCAG20-TECHS/H53.html) | object elements must contain text alternative | A-AAA | error | ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | html contains valid lang | A-AAA | error | ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | lang attribute of the document element does not appear to be well-formed | A-AAA | error | 3.Lang ||
Expand All @@ -29,6 +30,6 @@ List of [WCAG2.1 techniques](https://www.w3.org/TR/WCAG21/) and whether or not w
| [F47](https://www.w3.org/TR/WCAG20-TECHS/F47.html) | blink element used for attention | A-AAA | error | ||
| [F77](https://www.w3.org/TR/WCAG20-TECHS/F77.html) | duplicate ID found | A-AAA | error | ||

Errors that can be to be tested with automation `22/70`.
Errors that can be to be tested with automation `23/70`.

Key: ✅ = Complete, ✔️ = Complete with a bit of missing details.
6 changes: 3 additions & 3 deletions accessibility-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "accessibility-rs"
version = "0.0.39"
version = "0.0.40"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <jeff@a11ywatch.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -15,14 +15,14 @@ default = []

[dependencies]
lazy_static = { workspace = true }
accessibility-scraper = { version = "0.0.2", features = ["main"], default-features = false, path = "../accessibility-scraper" }
accessibility-scraper = { version = "0.0.4", features = ["main"], default-features = false, path = "../accessibility-scraper" }
accessibility-tree = { version = "0.0.4", path = "../accessibility-tree/victor" }
getrandom = { version = "0.2", features = ["js"] }
taffy = { version = "0.3.13" }
serde = { version = "1.0", features = ["derive"] }
selectors = { workspace = true }
smallvec = { workspace = true }
ego-tree = { workspace = true }
accessibility-tree = { version = "0.0.2", path = "../accessibility-tree/victor" }
markup5ever = "0.11.0"
cssparser = { workspace = true }
slotmap = "1.0.6"
Expand Down
4 changes: 4 additions & 0 deletions accessibility-rs/src/engine/rules/techniques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ pub enum Techniques {
H37,
/// <https://www.w3.org/TR/WCAG20-TECHS/H42>
H42,
/// <https://www.w3.org/TR/WCAG20-TECHS/H44>
H44,
/// <https://www.w3.org/TR/WCAG20-TECHS/H53>
H53,
/// <https://www.w3.org/TR/WCAG20-TECHS/H57>
H57,
/// <https://www.w3.org/TR/WCAG20-TECHS/H63>
H63,
/// <https://www.w3.org/TR/WCAG20-TECHS/H64>
H64,
/// <https://www.w3.org/TR/WCAG20-TECHS/H71>
Expand Down
27 changes: 27 additions & 0 deletions accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,33 @@ lazy_static! {
}

Validation::new(valid, "1", elements, Default::default()).into()
}),
Rule::new(Techniques::H44.into(), IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |nodes, _lang| {
let mut valid = true;
let mut elements = Vec::new();

for ele in nodes {
match ele.0.attr("for") {
Some(s) => {
let selector = unsafe { Selector::parse(&("#".to_string() + &s)).unwrap_unchecked() };
let root_tree = ele.0.tree().root();

match ElementRef::new(root_tree) {
t => {
let e = t.select(&selector);

if e.count() == 0 {
valid = false;
elements.push(get_unique_selector(&ele.0))
}
}
}
}
_ => ()
}
}

Validation::new(valid, "NonExistent", elements, Default::default()).into()
})
])),
("input", Vec::from([
Expand Down
17 changes: 17 additions & 0 deletions accessibility-rs/tests/unit/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ fn _audit_label_valid_name() {

assert_eq!(valid, false)
}

#[test]
/// label has id that does not exist
fn _audit_label_id_noexist() {
let markup = html! {
label for="accessibility" { "My label" }
input type="text" placeholder="Accessibility rocks!" value="Here";
};

let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string()));

let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle1.Guideline1_3.H44");

assert_eq!(valid, false)
}
6 changes: 3 additions & 3 deletions accessibility-scraper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "accessibility-scraper"
version = "0.0.2"
version = "0.0.4"
edition = "2021"

description = "HTML parsing and querying with CSS selectors"
description = "HTML parsing and querying with CSS selectors with CSS binding styles to elements."
keywords = ["html", "css", "selector", "scraping"]

authors = [
Expand All @@ -12,7 +12,7 @@ authors = [
]
license = "ISC"

repository = "https://github.com/accessibility-rs"
repository = "https://github.com/a11ywatch/accessibility-rs"
readme = "README.md"

[dependencies]
Expand Down
3 changes: 2 additions & 1 deletion accessibility-scraper/src/element_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub struct ElementRef<'a> {
}

impl<'a> ElementRef<'a> {
fn new(node: NodeRef<'a, Node>) -> Self {
/// Create a new element reference
pub fn new(node: NodeRef<'a, Node>) -> Self {
ElementRef { node }
}

Expand Down
10 changes: 5 additions & 5 deletions accessibility-tree/victor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "accessibility-tree"
version = "0.0.2"
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
version = "0.0.4"
authors = ["Jeff Mendez <jeff@a11ywatch.com"]
license = "MIT OR Apache-2.0"
description = "Victor makes vectors"
repository = "https://github.com/SimonSapin/victor"
description = "Accessibility tree binding CSS styles and vectors to elements. Used mainly for accessibility-rs crate."
repository = "https://github.com/a11ywatch/accessibility-rs"
edition = "2018"

[lib]
Expand All @@ -22,7 +22,7 @@ lock_api = "0.1"
num-traits = "0.2"
rayon = "1"
rayon_croissant = "0.1.1"
accessibility-scraper = { version = "0.0.2", features = ["main"], default-features = false, path = "../../accessibility-scraper" }
accessibility-scraper = { version = "0.0.4", features = ["main"], default-features = false, path = "../../accessibility-scraper" }
selectors = { workspace = true }
smallbitvec = "2.4"
smallvec = { workspace = true }
Expand Down

0 comments on commit 37ea0d6

Please sign in to comment.