From 7e032042cdffab226e5f65076442ac5b1424aac8 Mon Sep 17 00:00:00 2001 From: j-mendez Date: Thu, 12 Oct 2023 21:58:47 -0400 Subject: [PATCH] chore(locales): fix success criteria mapping --- Cargo.lock | 6 +-- accessibility-rs/Cargo.toml | 6 +-- accessibility-rs/src/engine/rules/rule.rs | 7 +-- .../src/engine/rules/wcag_rule_map.rs | 48 +++++++++---------- accessibility-rs/src/i18n/locales.rs | 2 +- accessibility-scraper/Cargo.toml | 5 +- accessibility-tree/victor/Cargo.toml | 4 +- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b712837..eb00433 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "accessibility-rs" -version = "0.0.18" +version = "0.0.19" dependencies = [ "accessibility-scraper", "accessibility-tree", @@ -26,7 +26,7 @@ dependencies = [ [[package]] name = "accessibility-scraper" -version = "0.0.1" +version = "0.0.2" dependencies = [ "ahash", "cssparser", @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "accessibility-tree" -version = "0.0.1" +version = "0.0.2" dependencies = [ "accessibility-scraper", "atomic_refcell", diff --git a/accessibility-rs/Cargo.toml b/accessibility-rs/Cargo.toml index e652bac..b445a9e 100644 --- a/accessibility-rs/Cargo.toml +++ b/accessibility-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-rs" -version = "0.0.18" +version = "0.0.19" authors = ["The A11yWatch Project Developers", "Jeff Mendez "] edition = "2021" license = "MIT OR Apache-2.0" @@ -15,14 +15,14 @@ default = [] [dependencies] lazy_static = { workspace = true } -accessibility-scraper = { version = "0.0.1", features = ["main"], default-features = false, path = "../accessibility-scraper" } +accessibility-scraper = { version = "0.0.2", features = ["main"], default-features = false, path = "../accessibility-scraper" } 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.1", path = "../accessibility-tree/victor" } +accessibility-tree = { version = "0.0.2", path = "../accessibility-tree/victor" } markup5ever = "0.11.0" cssparser = { workspace = true } slotmap = "1.0.6" diff --git a/accessibility-rs/src/engine/rules/rule.rs b/accessibility-rs/src/engine/rules/rule.rs index 062cc8d..445c86f 100644 --- a/accessibility-rs/src/engine/rules/rule.rs +++ b/accessibility-rs/src/engine/rules/rule.rs @@ -1,7 +1,7 @@ use slotmap::DefaultKey; use crate::engine::rules::techniques::Techniques; -use crate::engine::rules::wcag_base::{IssueType, Guideline, Principle}; +use crate::engine::rules::wcag_base::{Guideline, IssueType, Principle}; use crate::ElementRef; /// the validation response @@ -56,7 +56,7 @@ pub struct Rule { /// the guideline to follow pub guideline: Guideline, /// the success criteria - pub success_criteria: u8, + pub success_criteria: &'static str, } impl Rule { @@ -66,6 +66,7 @@ impl Rule { issue_type: IssueType, principle: Principle, guideline: Guideline, + success_criteria: &'static str, validate: fn(&str, &Vec<(ElementRef<'_>, Option)>) -> Validation, ) -> Rule { Rule { @@ -73,8 +74,8 @@ impl Rule { issue_type, guideline, principle, + success_criteria, validate, - success_criteria: 0 } } } diff --git a/accessibility-rs/src/engine/rules/wcag_rule_map.rs b/accessibility-rs/src/engine/rules/wcag_rule_map.rs index 6f32aa3..3ad2455 100644 --- a/accessibility-rs/src/engine/rules/wcag_rule_map.rs +++ b/accessibility-rs/src/engine/rules/wcag_rule_map.rs @@ -1,11 +1,11 @@ use crate::engine::rules::rule::{Rule, Validation}; use crate::engine::rules::techniques::Techniques; -use crate::engine::rules::wcag_base::{IssueType, Guideline, Principle}; -use crate::ElementRef; +use crate::engine::rules::wcag_base::{Guideline, IssueType, Principle}; use accessibility_scraper::Selector; use selectors::Element; use slotmap::DefaultKey; use std::collections::BTreeMap; +use crate::ElementRef; /// a valid alt attribute for image fn has_alt(ele: ElementRef<'_>) -> bool { @@ -41,11 +41,11 @@ lazy_static! { pub static ref RULES_A: BTreeMap<&'static str, Vec> = vec![ ("html", Vec::from([ - Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, |_rule, nodes| { + Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, "1", |_rule, nodes| { let n = nodes[0].0; Validation::new_issue(!n.attr("lang").unwrap_or_default().is_empty() || !n.attr("xml:lang").unwrap_or_default().is_empty(), "2") }), - Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, |_rule, nodes| { + Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, "1", |_rule, nodes| { let lang = nodes[0].0.attr("lang").unwrap_or_default(); let alphabetic = lang.chars().all(|x| x.is_alphabetic()); // @@ -57,7 +57,7 @@ lazy_static! { alphabetic && lang.len() < 12 }, "3.Lang") }), - Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, |_rule, nodes| { + Rule::new(Techniques::H57, IssueType::Error, Principle::Understandable, Guideline::Readable, "1", |_rule, nodes| { let lang = nodes[0].0.attr("xml:lang").unwrap_or_default(); let alphabetic = lang.chars().all(|x| x == '_' || x.is_alphabetic()); // @@ -71,7 +71,7 @@ lazy_static! { }), ])), ("meta", Vec::from([ - Rule::new(Techniques::F40, IssueType::Error, Principle::Operable, Guideline::EnoughTime, |_rule, nodes| { + Rule::new(Techniques::F40, IssueType::Error, Principle::Operable, Guideline::EnoughTime, "1", |_rule, nodes| { let mut valid = true; for node in nodes { @@ -87,7 +87,7 @@ lazy_static! { Validation::new_issue(valid, "2") }), - Rule::new(Techniques::F41, IssueType::Error, Principle::Understandable, Guideline::EnoughTime, |_rule, nodes| { + Rule::new(Techniques::F41, IssueType::Error, Principle::Understandable, Guideline::EnoughTime, "1", |_rule, nodes| { let mut valid = true; for node in nodes { @@ -105,30 +105,30 @@ lazy_static! { }), ])), ("title", Vec::from([ - Rule::new(Techniques::H25, IssueType::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + Rule::new(Techniques::H25, IssueType::Error, Principle::Operable, Guideline::Navigable, "1", |_rule, nodes| { Validation::new_issue(!nodes.is_empty(), "1.NoTitleEl") }), - Rule::new(Techniques::H25, IssueType::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + Rule::new(Techniques::H25, IssueType::Error, Principle::Operable, Guideline::Navigable, "1", |_rule, nodes| { Validation::new_issue(nodes.is_empty() || nodes[0].0.html().is_empty(), "1.EmptyTitle") }), ])), ("blink", Vec::from([ - Rule::new(Techniques::F47, IssueType::Error, Principle::Operable, Guideline::EnoughTime, |_rule, nodes| { + Rule::new(Techniques::F47, IssueType::Error, Principle::Operable, Guideline::EnoughTime, "2", |_rule, nodes| { Validation::new_issue(nodes.is_empty(), "") }), ])), ("iframe", Vec::from([ - Rule::new(Techniques::H64, IssueType::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + Rule::new(Techniques::H64, IssueType::Error, Principle::Operable, Guideline::Navigable, "1", |_rule, nodes| { Validation::new_issue(nodes.iter().all(|e| !e.0.attr("title").unwrap_or_default().is_empty()), "") }), ])), ("frame", Vec::from([ - Rule::new(Techniques::H64, IssueType::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + Rule::new(Techniques::H64, IssueType::Error, Principle::Operable, Guideline::Navigable, "1", |_rule, nodes| { Validation::new_issue(nodes.iter().all(|e| !e.0.attr("title").unwrap_or_default().is_empty()), "") }), ])), ("form", Vec::from([ - Rule::new(Techniques::H32, IssueType::Error, Principle::Operable, Guideline::Predictable, |_rule, nodes| { + Rule::new(Techniques::H32, IssueType::Error, Principle::Operable, Guideline::Predictable, "2", |_rule, nodes| { // check the first element for now let mut valid = false; let selector = unsafe { Selector::parse("button[type=submit]").unwrap_unchecked() }; @@ -143,7 +143,7 @@ lazy_static! { Validation::new_issue(valid, "2") }), - Rule::new(Techniques::H36, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, |_rule, nodes| { + Rule::new(Techniques::H36, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, "1", |_rule, nodes| { let mut valid = false; let selector = unsafe { Selector::parse("input[type=image][name=submit]").unwrap_unchecked() }; @@ -160,7 +160,7 @@ lazy_static! { }), ])), ("a", Vec::from([ - Rule::new(Techniques::H30, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, |_rule, nodes| { + Rule::new(Techniques::H30, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, "1", |_rule, nodes| { let mut valid = true; let selector = unsafe { Selector::parse("img").unwrap_unchecked() }; // todo: use tree to see if img exist to skip @@ -176,7 +176,7 @@ lazy_static! { Validation::new_issue(valid, "2") }), - Rule::new(Techniques::H91, IssueType::Error, Principle::Robust, Guideline::Compatible, |_rule, nodes| { + Rule::new(Techniques::H91, IssueType::Error, Principle::Robust, Guideline::Compatible, "2", |_rule, nodes| { let mut valid = true; for ele in nodes { let ele = ele.0; @@ -189,7 +189,7 @@ lazy_static! { } Validation::new_issue(valid, "A.NoContent") }), - Rule::new(Techniques::H91, IssueType::Error, Principle::Robust, Guideline::Compatible, |_rule, nodes| { + Rule::new(Techniques::H91, IssueType::Error, Principle::Robust, Guideline::Compatible, "2", |_rule, nodes| { let mut valid = true; for ele in nodes { let ele = ele.0; @@ -199,7 +199,7 @@ lazy_static! { }), ])), ("img", Vec::from([ - Rule::new(Techniques::H37, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, |_rule, nodes| { + Rule::new(Techniques::H37, IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, "1", |_rule, nodes| { let mut valid = true; for ele in nodes { @@ -211,32 +211,32 @@ lazy_static! { }), ])), ("h1", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])), ("h2", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])), ("h3", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])), ("h4", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])), ("h5", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])), ("h6", Vec::from([ - Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, |_rule, nodes| { + Rule::new(Techniques::H42, IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |_rule, nodes| { Validation::new_issue(!is_empty(nodes), Techniques::H42.pairs()[0]) }), ])) diff --git a/accessibility-rs/src/i18n/locales.rs b/accessibility-rs/src/i18n/locales.rs index e413d4d..f417c90 100644 --- a/accessibility-rs/src/i18n/locales.rs +++ b/accessibility-rs/src/i18n/locales.rs @@ -66,7 +66,7 @@ impl Langs { /// get message config type pub fn get_message_i18n(rule: &Rule, section: &str, lang: &str) -> String { // todo: add criteria handling fix - let base = [rule.guideline.as_index(), rule.principle.as_index()].join("_") + "_"; + let base = [rule.guideline.as_index(), rule.success_criteria].join("_") + "_"; let message = if section.is_empty() { [rule.rule_id.as_str()].join(".").to_string() } else { diff --git a/accessibility-scraper/Cargo.toml b/accessibility-scraper/Cargo.toml index 316ad58..26d86ed 100644 --- a/accessibility-scraper/Cargo.toml +++ b/accessibility-scraper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-scraper" -version = "0.0.1" +version = "0.0.2" edition = "2021" description = "HTML parsing and querying with CSS selectors" @@ -8,10 +8,11 @@ keywords = ["html", "css", "selector", "scraping"] authors = [ "June McEnroe ", + "Jeff Mendez ", ] license = "ISC" -repository = "https://github.com/causal-agent/scraper" +repository = "https://github.com/accessibility-rs" readme = "README.md" [dependencies] diff --git a/accessibility-tree/victor/Cargo.toml b/accessibility-tree/victor/Cargo.toml index e889495..4bde9f5 100644 --- a/accessibility-tree/victor/Cargo.toml +++ b/accessibility-tree/victor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-tree" -version = "0.0.1" +version = "0.0.2" authors = ["Simon Sapin "] license = "MIT OR Apache-2.0" description = "Victor makes vectors" @@ -22,7 +22,7 @@ lock_api = "0.1" num-traits = "0.2" rayon = "1" rayon_croissant = "0.1.1" -accessibility-scraper = { version = "0.0.1", features = ["main"], default-features = false, path = "../../accessibility-scraper" } +accessibility-scraper = { version = "0.0.2", features = ["main"], default-features = false, path = "../../accessibility-scraper" } selectors = { workspace = true } smallbitvec = "2.4" smallvec = { workspace = true }