| 1 | // Package axe carries the vendored axe-core engine and runs it in a |
| 2 | // page a browser drive is already on. The engine is test data: it is |
| 3 | // pinned and checksummed in README.md beside it, read by the |
| 4 | // accessibility drives, and never part of anything the root package |
| 5 | // ships. |
| 6 | // |
| 7 | // Run, the half that needs a browser, is build-tagged `browser`, as |
| 8 | // the harness is, so chromedp stays out of the plain build graph. |
| 9 | package axe |
| 10 | |
| 11 | import ( |
| 12 | _ "embed" |
| 13 | ) |
| 14 | |
| 15 | // script is axe.min.js, embedded so Run can hand it to the page as |
| 16 | // data. Only this package embeds it: the root package's tree is css/, |
| 17 | // js/, icons/ and LICENSE, and TestVendoredAxeIsThePinnedVersion |
| 18 | // holds the file to the README's pin. |
| 19 | // |
| 20 | //go:embed axe.min.js |
| 21 | var script string |
| 22 | |
| 23 | // Script returns the engine's source, for a drive that injects it |
| 24 | // into a document of its own (a preview frame, say) rather than the |
| 25 | // page Run scans. |
| 26 | func Script() string { return script } |
| 27 | |
| 28 | // defaultTags is the ruleset Scan uses when handed no tags, and it is |
| 29 | // not negotiable downwards. WCAG 2.2 AA is cumulative: 2.2 AA means |
| 30 | // every A and AA criterion from 2.0, 2.1 and 2.2, so all five tags |
| 31 | // have to be named or the older half of the standard silently stops |
| 32 | // being checked. |
| 33 | // |
| 34 | // Deliberately absent: best-practice, experimental and ACT tags. They |
| 35 | // are useful advice and they are not the standard the question asked |
| 36 | // about; mixing them in would make a failure mean two different |
| 37 | // things. |
| 38 | var defaultTags = []string{"wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"} |
| 39 | |
| 40 | // DefaultTags returns the ruleset Scan uses when handed no tags, as a |
| 41 | // copy: a caller that appends to or reslices what it gets changes |
| 42 | // nothing a later scan reads. |
| 43 | func DefaultTags() []string { return append([]string(nil), defaultTags...) } |
| 44 | |
| 45 | // Violation is one rule that found something: its id, axe's impact |
| 46 | // word, the one-line help text, and a selector for every node it |
| 47 | // found, so a failure names itself. |
| 48 | type Violation struct { |
| 49 | ID string |
| 50 | Impact string |
| 51 | Help string |
| 52 | Nodes []string |
| 53 | } |
| 54 | |