Skip to content

Commit

Permalink
chore(config): add reference config auditing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Jun 26, 2024
1 parent 8af7c56 commit 6441bc4
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 90 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ members = [
smallvec = "1"
selectors = "0.22.0"
cssparser = "0.27.0"
fast_html5ever = "0.26.1"
fast_html5ever = "0.26.6"
ego-tree = "0.6.2"
lazy_static = "1.4"
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Rust web accessibility engine.

```toml
[dependencies]
accessibility-rs = "^0.0.64"
accessibility-rs = "^0.1"
```

```rs
Expand All @@ -32,7 +32,7 @@ With the Tokio runtime.

```toml
[dependencies]
accessibility-rs = { version = "^0.0.64", features = ["tokio"]}
accessibility-rs = { version = "^0.1", features = ["tokio"]}
```

```rs
Expand Down Expand Up @@ -60,7 +60,7 @@ With the Spider full website crawling.

```toml
[dependencies]
accessibility-rs = { version = "^0.0.64", features = ["spider"]}
accessibility-rs = { version = "^0.1", features = ["spider"]}
```

```rs
Expand All @@ -74,6 +74,28 @@ async fn main() {
}
```

If you need to use concurrency use TendrilSink.

```rs
use accessibility_rs::{fast_html5ever, Auditor, Html};
use fast_html5ever::driver::{self, ParseOpts};
use tendril::TendrilSink;

let parser = driver::parse_document(
Html::new_document(),
ParseOpts::default(),
);
let document = parser.one("<html>MY html code </html>");

let auditor = Auditor::new(
&document, &"", false, &"en",
);

let issues =
accessibility_rs::engine::audit::wcag::WCAGAAA::audit(auditor)
.await;
```

### Documentation

[Module documentation with examples](https://docs.rs/accessibility-rs).
Expand All @@ -87,6 +109,7 @@ async fn main() {
1. i18n support for multiple languages.
1. Re-creating layout tree to get element position coordinates.
1. Crawling full websites lightning-fast using [spider](https://github.com/spider-rs/spider).
1. Low-level built to be used as an engine in browsers.

## [Benchmarks](./benches/)

Expand Down
12 changes: 6 additions & 6 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.64"
version = "0.1.9"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -12,11 +12,11 @@ include = ["/src", "../LICENSE_MIT", "../LICENSE_APACHE", "../README.md", "local

[dependencies]
lazy_static = { workspace = true }
accessibility-scraper = { version = "0.0.12", features = ["main"], default-features = false, path = "../accessibility-scraper" }
accessibility-tree = { version = "0.0.12", path = "../accessibility-tree/victor" }
accessibility-scraper = { version = "0.0.14", features = ["main"], default-features = false, path = "../accessibility-scraper" }
accessibility-tree = { version = "0.0.14", path = "../accessibility-tree/victor" }
getrandom = { version = "0.2", features = ["js"] }
taffy = { version = "0.4.0" }
serde = { version = "1.0", features = ["derive"] }
taffy = { version = "0.5" }
serde = { version = "1", features = ["derive"] }
selectors = { workspace = true }
smallvec = { workspace = true }
ego-tree = { workspace = true }
Expand All @@ -29,7 +29,7 @@ contrast = "0.1"
rgb = "0.8"
rayon = { version = "1", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
tokio = { version = "1", features = ["macros"], optional = true }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "parking_lot"], optional = true }
tokio-stream = { version = "0.1", optional = true }
spider = { version = "1.98.2", optional = true }

Expand Down
2 changes: 0 additions & 2 deletions accessibility-rs/src/engine/audit/wcag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::engine::issue::Issue;
use crate::engine::rules::rule::RuleValidation;
use crate::engine::rules::wcag_rule_map::RULES_A;
use crate::Auditor;
#[cfg(feature = "rayon")]
use rayon::prelude::*;

#[derive(Default)]
/// Baseline for all rules
Expand Down
2 changes: 1 addition & 1 deletion accessibility-rs/src/engine/rules/rule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::engine::rules::techniques::Techniques;
use crate::engine::rules::wcag_base::{Guideline, IssueType, Principle};
use crate::ElementRef;
use accessibility_scraper::ElementRef;

/// the validation response
#[derive(Default, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion accessibility-rs/src/engine/rules/utils/nodes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::engine::rules::rule::Validation;
use crate::ElementRef;
use accessibility_scraper::ElementRef;
use accessibility_scraper::Selector;
use selectors::Element;

Expand Down
8 changes: 4 additions & 4 deletions accessibility-rs/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mocks::mock;

#[test]
fn _audit() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
false,
Expand All @@ -17,7 +17,7 @@ fn _audit() {

#[test]
fn _audit_large() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_HTML_LARGE_PAGE,
&mock::MOCK_CSS_RULES_LARGE,
false,
Expand All @@ -28,7 +28,7 @@ fn _audit_large() {

#[test]
fn _audit_bounded() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
true,
Expand All @@ -39,7 +39,7 @@ fn _audit_bounded() {

#[test]
fn _audit_large_bounded() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_HTML_LARGE_PAGE,
&mock::MOCK_CSS_RULES_LARGE,
true,
Expand Down
22 changes: 13 additions & 9 deletions accessibility-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
//! #[cfg(not(feature = "tokio"))]
//! fn main() {
//! let config = AuditConfig::basic(r###"<html><body><h1>My Title</h1><input type="text" placeholder="Type me"></input><img src="tabby_cat.png"></img></body></html>"###);
//! let audit = audit(config);
//! let audit = audit(&config);
//! println!("{:?}", audit);
//! }
//!
//! #[cfg(all(feature = "tokio", not(feature = "spider")))]
//! #[tokio::main]
//! async fn main() {
//! let config = AuditConfig::basic(r###"<html><body><h1>My Title</h1><input type="text" placeholder="Type me"></input><img src="tabby_cat.png"></img></body></html>"###);
//! let audit = audit(config).await;
//! let audit = audit(&config).await;
//! println!("{:?}", audit);
//! }
//!
Expand All @@ -43,7 +43,7 @@
//! async fn main() {
//! let mut config = AuditConfig::default();
//! config.url = "https://example.com".into();
//! let audit = audit(config).await;
//! let audit = audit(&config).await;
//! println!("{:?}", audit);
//! }
//! ```
Expand All @@ -62,9 +62,13 @@ pub mod engine;
/// locales for translations.
pub mod i18n;

use crate::engine::audit::auditor::Auditor;
use crate::engine::issue::Issue;
use accessibility_scraper::ElementRef;
pub use accessibility_scraper;
pub use accessibility_scraper::fast_html5ever;
pub use accessibility_scraper::ElementRef;
pub use accessibility_scraper::Html;

pub use crate::engine::audit::auditor::Auditor;
pub use crate::engine::issue::Issue;

i18n!("locales", fallback = "en");

Expand Down Expand Up @@ -218,14 +222,14 @@ pub enum AuditResults {

/// audit a web page passing the html and css rules.
#[cfg(all(feature = "spider"))]
pub async fn audit(config: AuditConfig) -> AuditResults {
pub async fn audit(config: &AuditConfig) -> AuditResults {
if !config.url.is_empty() {
use spider::website::Website;
let mut website: Website = Website::new(&config.url);
let mut rx2: tokio::sync::broadcast::Receiver<spider::page::Page> =
website.subscribe(16).unwrap();
let bounding_box = config.bounding_box;
let locale = config.locale;
let locale = config.locale.clone();

let audits = tokio::spawn(async move {
let mut issues: spider::hashbrown::HashMap<String, Vec<Issue>> =
Expand Down Expand Up @@ -253,7 +257,7 @@ pub async fn audit(config: AuditConfig) -> AuditResults {

/// audit a web page passing the html and css rules.
#[cfg(not(feature = "tokio"))]
pub fn audit(config: AuditConfig) -> Vec<Issue> {
pub fn audit(config: &AuditConfig) -> Vec<Issue> {
let document = accessibility_scraper::Html::parse_document(&config.html);
let auditor = Auditor::new(&document, &config.css, config.bounding_box, &config.locale);
engine::audit::wcag::WCAGAAA::audit(auditor)
Expand Down
16 changes: 8 additions & 8 deletions accessibility-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mocks::mock;
#[cfg(feature = "tokio")]
#[tokio::test]
async fn _audit() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
false,
Expand All @@ -20,7 +20,7 @@ async fn _audit() {
#[test]
#[cfg(not(feature = "tokio"))]
fn _audit() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
false,
Expand All @@ -32,7 +32,7 @@ fn _audit() {
#[test]
#[cfg(not(feature = "tokio"))]
fn _audit_large() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_HTML_LARGE_PAGE,
&mock::MOCK_CSS_RULES_LARGE,
false,
Expand All @@ -44,7 +44,7 @@ fn _audit_large() {
#[test]
#[cfg(not(feature = "tokio"))]
fn _audit_with_layout() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
true,
Expand All @@ -56,7 +56,7 @@ fn _audit_with_layout() {
#[test]
#[cfg(not(feature = "tokio"))]
fn _audit_large_with_layout() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_HTML_LARGE_PAGE,
&mock::MOCK_CSS_RULES_LARGE,
true,
Expand All @@ -68,7 +68,7 @@ fn _audit_large_with_layout() {
#[test]
#[cfg(not(feature = "tokio"))]
fn _audit_xlarge() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_XLARGE_HTML,
&mock::MOCK_CSS_RULES_XLARGE,
false,
Expand All @@ -80,7 +80,7 @@ fn _audit_xlarge() {
#[tokio::test]
#[cfg(feature = "tokio")]
async fn _audit_xlarge() {
let report = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(&AuditConfig::new(
mock::MOCK_WEBSITE_XLARGE_HTML,
&mock::MOCK_CSS_RULES_XLARGE,
false,
Expand All @@ -94,6 +94,6 @@ async fn _audit_xlarge() {
#[tokio::test]
async fn _audit_website() {
let audit_config = AuditConfig::new_website("https://choosealicense.com", "", false, "");
let report = accessibility_rs::audit(audit_config).await;
let report = accessibility_rs::audit(&audit_config).await;
println!("{:?}", report)
}
8 changes: 4 additions & 4 deletions accessibility-rs/tests/unit/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use maud::html;
#[cfg(not(feature = "tokio"))]
/// anchor contains single img element without alt
fn _audit_missing_alt_anchor_img() {
let audit = accessibility_rs::audit(AuditConfig::basic(
let audit = accessibility_rs::audit(&AuditConfig::basic(
r###"<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Decrative Img: Do not use!</title>
Expand All @@ -33,7 +33,7 @@ fn _audit_missing_anchor_content_valid_href() {
let markup = html! {
a href="www.example.com";
};
let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string()));
let audit = accessibility_rs::audit(&AuditConfig::basic(&markup.into_string()));
let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");
Expand All @@ -48,7 +48,7 @@ fn _audit_missing_anchor_content() {
let markup = html! {
a { "" }
};
let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string()));
let audit = accessibility_rs::audit(&AuditConfig::basic(&markup.into_string()));
let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");
Expand All @@ -60,7 +60,7 @@ fn _audit_missing_anchor_content() {
#[cfg(not(feature = "tokio"))]
/// anchor text matches img alt
fn _audit_img_alt_matches_text_anchor() {
let audit = accessibility_rs::audit(AuditConfig::basic(
let audit = accessibility_rs::audit(&AuditConfig::basic(
r###"<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Decrative Img: Do not use!</title>
Expand Down
Loading

0 comments on commit 6441bc4

Please sign in to comment.