accessibility_rs/engine/
issue.rs

1use serde::{Deserialize, Serialize};
2
3/// clip bounding box
4#[derive(Default, Debug, Clone, Serialize, Deserialize)]
5pub struct Clip {
6    /// the x coords
7    pub x: u32,
8    /// the y coords
9    pub y: u32,
10    /// the element height
11    pub height: u32,
12    /// the element width
13    pub width: u32,
14}
15
16/// Extra help information for the issue
17#[derive(Default, Debug, Clone, Serialize, Deserialize)]
18pub struct RunnerExtras {
19    /// the url to get more information on the issue
20    pub help_url: &'static str,
21    /// a detailed description of the issue
22    pub description: &'static str,
23    /// the impact level criteria
24    pub impact: &'static str,
25}
26
27/// Details of the problem
28#[derive(Default, Debug, Clone, Serialize, Deserialize)]
29pub struct Issue {
30    /// the context of the issue or raw html
31    pub context: String,
32    /// the selector to identify the issue with css, xpath, or raw path
33    pub selectors: Vec<String>,
34    /// the type of code for the issue
35    pub code: String,
36    /// the type of issue
37    pub issue_type: &'static str,
38    /// the typecode of the issue 0,1,2
39    pub type_code: u8,
40    /// the message of the issue
41    pub message: String,
42    /// the type of runner
43    pub runner: &'static str,
44    /// extra details for the runner
45    pub runner_extras: RunnerExtras,
46    /// the amount of times the issue appeared
47    pub recurrence: u32,
48    /// the visual position of the element
49    pub clip: Option<Clip>,
50}
51
52impl Issue {
53    /// create a new issue
54    pub fn new(
55        message: String,
56        context: &str,
57        code: &str,
58        issue_type: &'static str,
59        selectors: Vec<String>,
60    ) -> Issue {
61        Issue {
62            message,
63            context: context.into(),
64            runner: "accessibility-rs",
65            code: code.into(),
66            issue_type,
67            type_code: match issue_type {
68                "error" => 0,
69                "warning" => 1,
70                _ => 2,
71            },
72            selectors,
73            ..Default::default()
74        }
75    }
76}