Skip to content

Commit

Permalink
chore(locales): fix success criteria mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 13, 2023
1 parent d24abaf commit 7e03204
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 38 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.

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.18"
version = "0.0.19"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <[email protected]>"]
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.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"
Expand Down
7 changes: 4 additions & 3 deletions accessibility-rs/src/engine/rules/rule.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -66,15 +66,16 @@ impl Rule {
issue_type: IssueType,
principle: Principle,
guideline: Guideline,
success_criteria: &'static str,
validate: fn(&str, &Vec<(ElementRef<'_>, Option<DefaultKey>)>) -> Validation,
) -> Rule {
Rule {
rule_id,
issue_type,
guideline,
principle,
success_criteria,
validate,
success_criteria: 0
}
}
}
48 changes: 24 additions & 24 deletions accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -41,11 +41,11 @@ lazy_static! {
pub static ref RULES_A: BTreeMap<&'static str, Vec<Rule>> =
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());
// <https://www.rfc-editor.org/rfc/bcp/bcp47.txt>
Expand All @@ -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());
// <https://www.rfc-editor.org/rfc/bcp/bcp47.txt>
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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() };
Expand All @@ -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() };

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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])
}),
]))
Expand Down
2 changes: 1 addition & 1 deletion accessibility-rs/src/i18n/locales.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions accessibility-scraper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[package]
name = "accessibility-scraper"
version = "0.0.1"
version = "0.0.2"
edition = "2021"

description = "HTML parsing and querying with CSS selectors"
keywords = ["html", "css", "selector", "scraping"]

authors = [
"June McEnroe <[email protected]>",
"Jeff Mendez <[email protected]>",
]
license = "ISC"

repository = "https://github.com/causal-agent/scraper"
repository = "https://github.com/accessibility-rs"
readme = "README.md"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions accessibility-tree/victor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "accessibility-tree"
version = "0.0.1"
version = "0.0.2"
authors = ["Simon Sapin <[email protected]>"]
license = "MIT OR Apache-2.0"
description = "Victor makes vectors"
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.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 }
Expand Down

0 comments on commit 7e03204

Please sign in to comment.