axe-core 4.1.2-canary.ec00dc7 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (640) hide show
  1. package/CHANGELOG.md +0 -46
  2. package/CONTRIBUTING.md +57 -112
  3. package/README.md +50 -59
  4. package/axe.d.ts +281 -282
  5. package/axe.js +678 -1285
  6. package/axe.min.js +2 -2
  7. package/bower.json +38 -44
  8. package/doc/API.md +133 -178
  9. package/doc/check-message-template.md +3 -3
  10. package/doc/check-options.md +25 -25
  11. package/doc/developer-guide.md +48 -48
  12. package/doc/examples/chrome-debugging-protocol/axe-cdp.js +56 -56
  13. package/doc/examples/chrome-debugging-protocol/package.json +9 -9
  14. package/doc/examples/html-handlebars.md +52 -52
  15. package/doc/examples/jasmine/karma.conf.js +15 -15
  16. package/doc/examples/jasmine/package.json +19 -19
  17. package/doc/examples/jasmine/spec/a11y.js +29 -29
  18. package/doc/examples/jest_react/link.js +3 -3
  19. package/doc/examples/jest_react/link.test.js +15 -15
  20. package/doc/examples/jest_react/package.json +26 -26
  21. package/doc/examples/jest_react/test-helpers.js +12 -12
  22. package/doc/examples/jsdom/package.json +13 -13
  23. package/doc/examples/mocha/karma.conf.js +15 -15
  24. package/doc/examples/mocha/package.json +20 -20
  25. package/doc/examples/phantomjs/axe-phantom.js +36 -36
  26. package/doc/examples/phantomjs/package.json +17 -17
  27. package/doc/examples/puppeteer/axe-puppeteer.js +37 -37
  28. package/doc/examples/puppeteer/package.json +11 -11
  29. package/doc/examples/qunit/package.json +19 -19
  30. package/doc/examples/test-examples.js +22 -22
  31. package/doc/plugins.md +64 -64
  32. package/doc/projects.md +9 -13
  33. package/doc/rule-descriptions.md +100 -104
  34. package/doc/rule-development.md +2 -2
  35. package/doc/standards-object.md +8 -14
  36. package/lib/checks/aria/abstractrole-evaluate.js +8 -8
  37. package/lib/checks/aria/abstractrole.json +12 -12
  38. package/lib/checks/aria/aria-allowed-attr-evaluate.js +25 -24
  39. package/lib/checks/aria/aria-allowed-attr.json +12 -12
  40. package/lib/checks/aria/aria-allowed-role-evaluate.js +21 -21
  41. package/lib/checks/aria/aria-allowed-role.json +20 -20
  42. package/lib/checks/aria/aria-errormessage-evaluate.js +30 -38
  43. package/lib/checks/aria/aria-errormessage.json +16 -16
  44. package/lib/checks/aria/aria-hidden-body-evaluate.js +1 -1
  45. package/lib/checks/aria/aria-hidden-body.json +9 -9
  46. package/lib/checks/aria/aria-required-attr-evaluate.js +34 -34
  47. package/lib/checks/aria/aria-required-attr.json +12 -12
  48. package/lib/checks/aria/aria-required-children-evaluate.js +103 -108
  49. package/lib/checks/aria/aria-required-children.json +30 -30
  50. package/lib/checks/aria/aria-required-parent-evaluate.js +65 -72
  51. package/lib/checks/aria/aria-required-parent.json +12 -12
  52. package/lib/checks/aria/aria-roledescription-evaluate.js +9 -9
  53. package/lib/checks/aria/aria-roledescription.json +21 -21
  54. package/lib/checks/aria/aria-unsupported-attr-evaluate.js +20 -17
  55. package/lib/checks/aria/aria-unsupported-attr.json +9 -9
  56. package/lib/checks/aria/aria-valid-attr-evaluate.js +20 -20
  57. package/lib/checks/aria/aria-valid-attr-value-evaluate.js +71 -82
  58. package/lib/checks/aria/aria-valid-attr-value.json +17 -17
  59. package/lib/checks/aria/aria-valid-attr.json +13 -13
  60. package/lib/checks/aria/fallbackrole-evaluate.js +1 -1
  61. package/lib/checks/aria/fallbackrole.json +9 -9
  62. package/lib/checks/aria/has-global-aria-attribute-evaluate.js +5 -5
  63. package/lib/checks/aria/has-global-aria-attribute.json +12 -12
  64. package/lib/checks/aria/has-widget-role-evaluate.js +6 -6
  65. package/lib/checks/aria/has-widget-role.json +10 -10
  66. package/lib/checks/aria/invalidrole-evaluate.js +12 -12
  67. package/lib/checks/aria/invalidrole.json +12 -12
  68. package/lib/checks/aria/is-element-focusable-evaluate.js +1 -1
  69. package/lib/checks/aria/is-element-focusable.json +9 -9
  70. package/lib/checks/aria/no-implicit-explicit-label-evaluate.js +18 -20
  71. package/lib/checks/aria/no-implicit-explicit-label.json +9 -9
  72. package/lib/checks/aria/unsupportedrole-evaluate.js +2 -2
  73. package/lib/checks/aria/unsupportedrole.json +9 -9
  74. package/lib/checks/aria/valid-scrollable-semantics-evaluate.js +23 -23
  75. package/lib/checks/aria/valid-scrollable-semantics.json +10 -10
  76. package/lib/checks/color/color-contrast-evaluate.js +164 -164
  77. package/lib/checks/color/color-contrast.json +40 -40
  78. package/lib/checks/color/link-in-text-block-evaluate.js +70 -70
  79. package/lib/checks/color/link-in-text-block.json +17 -17
  80. package/lib/checks/forms/autocomplete-appropriate-evaluate.js +68 -68
  81. package/lib/checks/forms/autocomplete-appropriate.json +9 -9
  82. package/lib/checks/forms/autocomplete-valid-evaluate.js +2 -2
  83. package/lib/checks/forms/autocomplete-valid.json +9 -9
  84. package/lib/checks/generic/README.md +5 -5
  85. package/lib/checks/generic/attr-non-space-content-evaluate.js +20 -20
  86. package/lib/checks/generic/has-descendant-after.js +10 -10
  87. package/lib/checks/generic/has-descendant-evaluate.js +12 -12
  88. package/lib/checks/generic/has-text-content-evaluate.js +5 -5
  89. package/lib/checks/generic/matches-definition-evaluate.js +1 -1
  90. package/lib/checks/generic/page-no-duplicate-after.js +2 -2
  91. package/lib/checks/generic/page-no-duplicate-evaluate.js +29 -29
  92. package/lib/checks/keyboard/accesskeys-after.js +19 -19
  93. package/lib/checks/keyboard/accesskeys-evaluate.js +5 -5
  94. package/lib/checks/keyboard/accesskeys.json +10 -10
  95. package/lib/checks/keyboard/focusable-content-evaluate.js +13 -13
  96. package/lib/checks/keyboard/focusable-content.json +9 -9
  97. package/lib/checks/keyboard/focusable-disabled-evaluate.js +30 -30
  98. package/lib/checks/keyboard/focusable-disabled.json +9 -9
  99. package/lib/checks/keyboard/focusable-element-evaluate.js +41 -41
  100. package/lib/checks/keyboard/focusable-element.json +9 -9
  101. package/lib/checks/keyboard/focusable-modal-open-evaluate.js +11 -11
  102. package/lib/checks/keyboard/focusable-modal-open.json +9 -9
  103. package/lib/checks/keyboard/focusable-no-name-evaluate.js +10 -10
  104. package/lib/checks/keyboard/focusable-no-name.json +10 -10
  105. package/lib/checks/keyboard/focusable-not-tabbable-evaluate.js +30 -30
  106. package/lib/checks/keyboard/focusable-not-tabbable.json +9 -9
  107. package/lib/checks/keyboard/landmark-is-top-level-evaluate.js +17 -22
  108. package/lib/checks/keyboard/landmark-is-top-level.json +9 -9
  109. package/lib/checks/keyboard/page-has-heading-one.json +13 -13
  110. package/lib/checks/keyboard/page-has-main.json +13 -13
  111. package/lib/checks/keyboard/page-no-duplicate-banner.json +14 -14
  112. package/lib/checks/keyboard/page-no-duplicate-contentinfo.json +14 -14
  113. package/lib/checks/keyboard/page-no-duplicate-main.json +13 -13
  114. package/lib/checks/keyboard/tabindex-evaluate.js +5 -5
  115. package/lib/checks/keyboard/tabindex.json +9 -9
  116. package/lib/checks/label/alt-space-value-evaluate.js +3 -3
  117. package/lib/checks/label/alt-space-value.json +9 -9
  118. package/lib/checks/label/duplicate-img-label-evaluate.js +12 -12
  119. package/lib/checks/label/duplicate-img-label.json +12 -12
  120. package/lib/checks/label/explicit-evaluate.js +20 -25
  121. package/lib/checks/label/explicit.json +10 -10
  122. package/lib/checks/label/help-same-as-label-evaluate.js +17 -17
  123. package/lib/checks/label/help-same-as-label.json +10 -10
  124. package/lib/checks/label/hidden-explicit-label-evaluate.js +15 -21
  125. package/lib/checks/label/hidden-explicit-label.json +10 -10
  126. package/lib/checks/label/implicit-evaluate.js +9 -9
  127. package/lib/checks/label/implicit.json +10 -10
  128. package/lib/checks/label/label-content-name-mismatch-evaluate.js +42 -42
  129. package/lib/checks/label/label-content-name-mismatch.json +13 -13
  130. package/lib/checks/label/multiple-label-evaluate.js +32 -32
  131. package/lib/checks/label/multiple-label.json +9 -9
  132. package/lib/checks/label/title-only-evaluate.js +4 -4
  133. package/lib/checks/label/title-only.json +9 -9
  134. package/lib/checks/landmarks/landmark-is-unique-after.js +20 -20
  135. package/lib/checks/landmarks/landmark-is-unique-evaluate.js +6 -6
  136. package/lib/checks/landmarks/landmark-is-unique.json +10 -10
  137. package/lib/checks/language/has-lang-evaluate.js +25 -25
  138. package/lib/checks/language/has-lang.json +15 -15
  139. package/lib/checks/language/valid-lang-evaluate.js +25 -25
  140. package/lib/checks/language/valid-lang.json +12 -12
  141. package/lib/checks/language/xml-lang-mismatch-evaluate.js +3 -3
  142. package/lib/checks/language/xml-lang-mismatch.json +9 -9
  143. package/lib/checks/lists/dlitem-evaluate.js +19 -19
  144. package/lib/checks/lists/dlitem.json +9 -9
  145. package/lib/checks/lists/listitem-evaluate.js +17 -17
  146. package/lib/checks/lists/listitem.json +12 -12
  147. package/lib/checks/lists/only-dlitems-evaluate.js +44 -44
  148. package/lib/checks/lists/only-dlitems.json +9 -9
  149. package/lib/checks/lists/only-listitems-evaluate.js +56 -56
  150. package/lib/checks/lists/only-listitems.json +12 -12
  151. package/lib/checks/lists/structured-dlitems-evaluate.js +20 -20
  152. package/lib/checks/lists/structured-dlitems.json +9 -9
  153. package/lib/checks/media/caption-evaluate.js +6 -6
  154. package/lib/checks/media/caption.json +9 -9
  155. package/lib/checks/media/frame-tested-evaluate.js +20 -20
  156. package/lib/checks/media/frame-tested.json +13 -13
  157. package/lib/checks/media/no-autoplay-audio-evaluate.js +81 -81
  158. package/lib/checks/media/no-autoplay-audio.json +13 -13
  159. package/lib/checks/mobile/css-orientation-lock-evaluate.js +250 -250
  160. package/lib/checks/mobile/css-orientation-lock.json +13 -13
  161. package/lib/checks/mobile/meta-viewport-large.json +13 -13
  162. package/lib/checks/mobile/meta-viewport-scale-evaluate.js +56 -56
  163. package/lib/checks/mobile/meta-viewport.json +12 -12
  164. package/lib/checks/navigation/header-present.json +13 -13
  165. package/lib/checks/navigation/heading-order-after.js +11 -134
  166. package/lib/checks/navigation/heading-order-evaluate.js +13 -51
  167. package/lib/checks/navigation/heading-order.json +10 -10
  168. package/lib/checks/navigation/identical-links-same-purpose-after.js +86 -86
  169. package/lib/checks/navigation/identical-links-same-purpose-evaluate.js +23 -23
  170. package/lib/checks/navigation/identical-links-same-purpose.json +10 -10
  171. package/lib/checks/navigation/internal-link-present-evaluate.js +4 -4
  172. package/lib/checks/navigation/internal-link-present.json +9 -9
  173. package/lib/checks/navigation/landmark.json +12 -12
  174. package/lib/checks/navigation/meta-refresh-evaluate.js +3 -3
  175. package/lib/checks/navigation/meta-refresh.json +9 -9
  176. package/lib/checks/navigation/p-as-heading-evaluate.js +72 -72
  177. package/lib/checks/navigation/p-as-heading.json +28 -28
  178. package/lib/checks/navigation/region-evaluate.js +73 -73
  179. package/lib/checks/navigation/region.json +12 -12
  180. package/lib/checks/navigation/skip-link-evaluate.js +5 -5
  181. package/lib/checks/navigation/skip-link.json +10 -10
  182. package/lib/checks/navigation/unique-frame-title-after.js +8 -8
  183. package/lib/checks/navigation/unique-frame-title-evaluate.js +3 -3
  184. package/lib/checks/navigation/unique-frame-title.json +10 -10
  185. package/lib/checks/parsing/duplicate-id-active.json +10 -10
  186. package/lib/checks/parsing/duplicate-id-after.js +8 -8
  187. package/lib/checks/parsing/duplicate-id-aria.json +10 -10
  188. package/lib/checks/parsing/duplicate-id-evaluate.js +15 -15
  189. package/lib/checks/parsing/duplicate-id.json +10 -10
  190. package/lib/checks/shared/aria-label-evaluate.js +1 -1
  191. package/lib/checks/shared/aria-label.json +9 -9
  192. package/lib/checks/shared/aria-labelledby-evaluate.js +5 -5
  193. package/lib/checks/shared/aria-labelledby.json +10 -10
  194. package/lib/checks/shared/avoid-inline-spacing-evaluate.js +10 -10
  195. package/lib/checks/shared/avoid-inline-spacing.json +15 -15
  196. package/lib/checks/shared/button-has-visible-text.json +10 -10
  197. package/lib/checks/shared/doc-has-title-evaluate.js +2 -2
  198. package/lib/checks/shared/doc-has-title.json +9 -9
  199. package/lib/checks/shared/exists-evaluate.js +1 -1
  200. package/lib/checks/shared/exists.json +9 -9
  201. package/lib/checks/shared/has-alt-evaluate.js +5 -5
  202. package/lib/checks/shared/has-alt.json +9 -9
  203. package/lib/checks/shared/has-visible-text.json +10 -10
  204. package/lib/checks/shared/is-on-screen-evaluate.js +2 -2
  205. package/lib/checks/shared/is-on-screen.json +9 -9
  206. package/lib/checks/shared/non-empty-alt.json +15 -15
  207. package/lib/checks/shared/non-empty-if-present-evaluate.js +13 -13
  208. package/lib/checks/shared/non-empty-if-present.json +12 -12
  209. package/lib/checks/shared/non-empty-placeholder.json +15 -15
  210. package/lib/checks/shared/non-empty-title.json +15 -15
  211. package/lib/checks/shared/non-empty-value.json +15 -15
  212. package/lib/checks/shared/presentational-role-evaluate.js +29 -29
  213. package/lib/checks/shared/presentational-role.json +14 -14
  214. package/lib/checks/shared/role-none.json +17 -17
  215. package/lib/checks/shared/role-presentation.json +17 -17
  216. package/lib/checks/shared/svg-non-empty-title-evaluate.js +20 -24
  217. package/lib/checks/shared/svg-non-empty-title.json +13 -13
  218. package/lib/checks/tables/caption-faked-evaluate.js +8 -8
  219. package/lib/checks/tables/caption-faked.json +9 -9
  220. package/lib/checks/tables/html5-scope-evaluate.js +4 -4
  221. package/lib/checks/tables/html5-scope.json +9 -9
  222. package/lib/checks/tables/same-caption-summary-evaluate.js +6 -6
  223. package/lib/checks/tables/same-caption-summary.json +9 -9
  224. package/lib/checks/tables/scope-value-evaluate.js +2 -2
  225. package/lib/checks/tables/scope-value.json +12 -12
  226. package/lib/checks/tables/td-has-header-evaluate.js +21 -21
  227. package/lib/checks/tables/td-has-header.json +9 -9
  228. package/lib/checks/tables/td-headers-attr-evaluate.js +48 -48
  229. package/lib/checks/tables/td-headers-attr.json +10 -10
  230. package/lib/checks/tables/th-has-data-cells-evaluate.js +64 -64
  231. package/lib/checks/tables/th-has-data-cells.json +10 -10
  232. package/lib/checks/visibility/hidden-content-evaluate.js +28 -28
  233. package/lib/checks/visibility/hidden-content.json +10 -10
  234. package/lib/commons/aria/allowed-attr.js +12 -12
  235. package/lib/commons/aria/arialabel-text.js +7 -7
  236. package/lib/commons/aria/arialabelledby-text.js +41 -41
  237. package/lib/commons/aria/get-accessible-refs.js +41 -41
  238. package/lib/commons/aria/get-element-unallowed-roles.js +69 -69
  239. package/lib/commons/aria/get-explicit-role.js +14 -14
  240. package/lib/commons/aria/get-owned-virtual.js +14 -14
  241. package/lib/commons/aria/get-role-type.js +5 -5
  242. package/lib/commons/aria/get-role.js +89 -89
  243. package/lib/commons/aria/get-roles-by-type.js +1 -1
  244. package/lib/commons/aria/get-roles-with-name-from-contents.js +1 -1
  245. package/lib/commons/aria/implicit-nodes.js +6 -6
  246. package/lib/commons/aria/implicit-role.js +32 -32
  247. package/lib/commons/aria/is-accessible-ref.js +1 -1
  248. package/lib/commons/aria/is-aria-role-allowed-on-element.js +12 -12
  249. package/lib/commons/aria/is-unsupported-role.js +2 -2
  250. package/lib/commons/aria/is-valid-role.js +6 -6
  251. package/lib/commons/aria/label-virtual.js +24 -24
  252. package/lib/commons/aria/label.js +2 -2
  253. package/lib/commons/aria/lookup-table.js +2395 -2395
  254. package/lib/commons/aria/named-from-contents.js +19 -19
  255. package/lib/commons/aria/required-attr.js +5 -5
  256. package/lib/commons/aria/required-context.js +5 -5
  257. package/lib/commons/aria/required-owned.js +5 -5
  258. package/lib/commons/aria/validate-attr-value.js +40 -44
  259. package/lib/commons/aria/validate-attr.js +2 -2
  260. package/lib/commons/color/center-point-of-rect.js +15 -15
  261. package/lib/commons/color/color.js +224 -224
  262. package/lib/commons/color/element-has-image.js +14 -14
  263. package/lib/commons/color/element-is-distinct.js +56 -55
  264. package/lib/commons/color/filtered-rect-stack.js +32 -32
  265. package/lib/commons/color/flatten-colors.js +6 -6
  266. package/lib/commons/color/get-background-color.js +40 -40
  267. package/lib/commons/color/get-background-stack.js +71 -71
  268. package/lib/commons/color/get-contrast.js +9 -9
  269. package/lib/commons/color/get-foreground-color.js +34 -34
  270. package/lib/commons/color/get-own-background-color.js +7 -7
  271. package/lib/commons/color/get-rect-stack.js +14 -14
  272. package/lib/commons/color/get-text-shadow-colors.js +87 -87
  273. package/lib/commons/color/has-valid-contrast-ratio.js +10 -10
  274. package/lib/commons/color/incomplete-data.js +37 -37
  275. package/lib/commons/dom/find-elms-in-context.js +11 -11
  276. package/lib/commons/dom/find-up-virtual.js +31 -31
  277. package/lib/commons/dom/find-up.js +1 -1
  278. package/lib/commons/dom/focus-disabled.js +13 -13
  279. package/lib/commons/dom/get-composed-parent.js +14 -14
  280. package/lib/commons/dom/get-element-by-reference.js +18 -18
  281. package/lib/commons/dom/get-element-coordinates.js +12 -12
  282. package/lib/commons/dom/get-element-stack.js +10 -10
  283. package/lib/commons/dom/get-rect-stack.js +427 -427
  284. package/lib/commons/dom/get-scroll-offset.js +17 -17
  285. package/lib/commons/dom/get-tabbable-elements.js +9 -9
  286. package/lib/commons/dom/get-text-element-stack.js +49 -64
  287. package/lib/commons/dom/get-viewport-size.js +19 -19
  288. package/lib/commons/dom/has-content-virtual.js +29 -29
  289. package/lib/commons/dom/has-content.js +2 -2
  290. package/lib/commons/dom/idrefs.js +15 -15
  291. package/lib/commons/dom/inserted-into-focus-order.js +6 -6
  292. package/lib/commons/dom/is-focusable.js +12 -16
  293. package/lib/commons/dom/is-hidden-with-css.js +47 -47
  294. package/lib/commons/dom/is-html5.js +5 -5
  295. package/lib/commons/dom/is-in-text-block.js +74 -74
  296. package/lib/commons/dom/is-modal-open.js +78 -78
  297. package/lib/commons/dom/is-natively-focusable.js +22 -22
  298. package/lib/commons/dom/is-node.js +1 -1
  299. package/lib/commons/dom/is-offscreen.js +43 -43
  300. package/lib/commons/dom/is-opaque.js +4 -4
  301. package/lib/commons/dom/is-skip-link.js +27 -27
  302. package/lib/commons/dom/is-visible.js +147 -147
  303. package/lib/commons/dom/is-visual-content.js +33 -33
  304. package/lib/commons/dom/reduce-to-elements-below-floating.js +18 -18
  305. package/lib/commons/dom/shadow-elements-from-point.js +29 -29
  306. package/lib/commons/dom/url-props-from-attribute.js +100 -100
  307. package/lib/commons/dom/visually-contains.js +77 -77
  308. package/lib/commons/dom/visually-overlaps.js +29 -29
  309. package/lib/commons/forms/is-aria-combobox.js +2 -2
  310. package/lib/commons/forms/is-aria-listbox.js +2 -2
  311. package/lib/commons/forms/is-aria-range.js +2 -2
  312. package/lib/commons/forms/is-aria-textbox.js +2 -2
  313. package/lib/commons/forms/is-disabled.js +20 -20
  314. package/lib/commons/forms/is-native-select.js +3 -3
  315. package/lib/commons/forms/is-native-textbox.js +17 -17
  316. package/lib/commons/index.js +9 -9
  317. package/lib/commons/matches/attributes.js +4 -4
  318. package/lib/commons/matches/condition.js +1 -1
  319. package/lib/commons/matches/explicit-role.js +1 -1
  320. package/lib/commons/matches/from-definition.js +30 -30
  321. package/lib/commons/matches/from-function.js +12 -12
  322. package/lib/commons/matches/from-primative.js +20 -20
  323. package/lib/commons/matches/implicit-role.js +1 -1
  324. package/lib/commons/matches/matches.js +1 -1
  325. package/lib/commons/matches/node-name.js +4 -4
  326. package/lib/commons/matches/properties.js +4 -4
  327. package/lib/commons/matches/semantic-role.js +1 -1
  328. package/lib/commons/standards/get-aria-roles-by-type.js +3 -3
  329. package/lib/commons/standards/get-aria-roles-supporting-name-from-content.js +8 -8
  330. package/lib/commons/standards/get-element-spec.js +42 -42
  331. package/lib/commons/standards/get-elements-by-content-type.js +15 -15
  332. package/lib/commons/standards/get-global-aria-attrs.js +8 -8
  333. package/lib/commons/standards/implicit-html-roles.js +140 -140
  334. package/lib/commons/table/get-all-cells.js +16 -16
  335. package/lib/commons/table/get-cell-position.js +15 -15
  336. package/lib/commons/table/get-headers.js +65 -72
  337. package/lib/commons/table/get-scope.js +42 -42
  338. package/lib/commons/table/is-column-header.js +1 -1
  339. package/lib/commons/table/is-data-cell.js +10 -10
  340. package/lib/commons/table/is-data-table.js +176 -176
  341. package/lib/commons/table/is-header.js +8 -8
  342. package/lib/commons/table/is-row-header.js +1 -1
  343. package/lib/commons/table/to-grid.js +20 -31
  344. package/lib/commons/table/traverse.js +55 -55
  345. package/lib/commons/text/accessible-text-virtual.js +90 -90
  346. package/lib/commons/text/accessible-text.js +2 -2
  347. package/lib/commons/text/form-control-value.js +112 -113
  348. package/lib/commons/text/has-unicode.js +17 -17
  349. package/lib/commons/text/index.js +4 -4
  350. package/lib/commons/text/is-human-interpretable.js +34 -34
  351. package/lib/commons/text/is-icon-ligature.js +194 -194
  352. package/lib/commons/text/is-valid-autocomplete.js +104 -104
  353. package/lib/commons/text/label-text.js +39 -39
  354. package/lib/commons/text/label-virtual.js +26 -26
  355. package/lib/commons/text/label.js +2 -2
  356. package/lib/commons/text/native-element-type.js +97 -97
  357. package/lib/commons/text/native-text-alternative.js +19 -19
  358. package/lib/commons/text/native-text-methods.js +113 -113
  359. package/lib/commons/text/remove-unicode.js +15 -15
  360. package/lib/commons/text/sanitize.js +8 -8
  361. package/lib/commons/text/subtree-text.js +89 -47
  362. package/lib/commons/text/title-text.js +14 -14
  363. package/lib/commons/text/unicode.js +56 -56
  364. package/lib/commons/text/unsupported.js +1 -1
  365. package/lib/commons/text/visible-text-nodes.js +12 -12
  366. package/lib/commons/text/visible-virtual.js +21 -21
  367. package/lib/commons/text/visible.js +2 -2
  368. package/lib/core/base/audit.js +613 -613
  369. package/lib/core/base/cache.js +22 -22
  370. package/lib/core/base/check-result.js +20 -20
  371. package/lib/core/base/check.js +132 -132
  372. package/lib/core/base/context.js +175 -179
  373. package/lib/core/base/metadata-function-map.js +167 -179
  374. package/lib/core/base/rule-result.js +25 -25
  375. package/lib/core/base/rule.js +473 -475
  376. package/lib/core/base/virtual-node/abstract-virtual-node.js +33 -37
  377. package/lib/core/base/virtual-node/serial-virtual-node.js +76 -85
  378. package/lib/core/base/virtual-node/virtual-node.js +151 -177
  379. package/lib/core/constants.js +50 -50
  380. package/lib/core/core.js +7 -11
  381. package/lib/core/imports/index.js +14 -14
  382. package/lib/core/index.js +21 -19
  383. package/lib/core/log.js +4 -4
  384. package/lib/core/public/cleanup.js +43 -41
  385. package/lib/core/public/configure.js +112 -112
  386. package/lib/core/public/get-rules.js +19 -19
  387. package/lib/core/public/load.js +49 -47
  388. package/lib/core/public/plugins.js +24 -22
  389. package/lib/core/public/reporter.js +12 -12
  390. package/lib/core/public/reset.js +6 -6
  391. package/lib/core/public/run-rules.js +76 -61
  392. package/lib/core/public/run-virtual-rule.js +42 -47
  393. package/lib/core/public/run.js +154 -154
  394. package/lib/core/reporters/helpers/failure-summary.js +22 -22
  395. package/lib/core/reporters/helpers/get-environment-data.js +29 -29
  396. package/lib/core/reporters/helpers/incomplete-fallback-msg.js +3 -3
  397. package/lib/core/reporters/helpers/index.js +8 -8
  398. package/lib/core/reporters/helpers/process-aggregate.js +69 -69
  399. package/lib/core/reporters/na.js +16 -16
  400. package/lib/core/reporters/no-passes.js +12 -12
  401. package/lib/core/reporters/raw-env.js +9 -9
  402. package/lib/core/reporters/raw.js +24 -24
  403. package/lib/core/reporters/v1.js +23 -23
  404. package/lib/core/reporters/v2.js +13 -13
  405. package/lib/core/utils/aggregate-checks.js +63 -63
  406. package/lib/core/utils/aggregate-node-results.js +44 -44
  407. package/lib/core/utils/aggregate-result.js +24 -24
  408. package/lib/core/utils/aggregate.js +6 -6
  409. package/lib/core/utils/are-styles-set.js +14 -14
  410. package/lib/core/utils/assert.js +3 -3
  411. package/lib/core/utils/check-helper.js +23 -23
  412. package/lib/core/utils/clone.js +18 -18
  413. package/lib/core/utils/closest.js +12 -12
  414. package/lib/core/utils/collect-results-from-frames.js +45 -63
  415. package/lib/core/utils/contains.js +29 -29
  416. package/lib/core/utils/css-parser.js +0 -1
  417. package/lib/core/utils/deep-merge.js +18 -18
  418. package/lib/core/utils/dq-element.js +88 -88
  419. package/lib/core/utils/element-matches.js +29 -29
  420. package/lib/core/utils/escape-selector.js +63 -63
  421. package/lib/core/utils/extend-meta-data.js +11 -11
  422. package/lib/core/utils/finalize-result.js +13 -15
  423. package/lib/core/utils/find-by.js +3 -3
  424. package/lib/core/utils/get-all-checks.js +5 -5
  425. package/lib/core/utils/get-ancestry.js +16 -16
  426. package/lib/core/utils/get-base-lang.js +7 -7
  427. package/lib/core/utils/get-check-message.js +9 -9
  428. package/lib/core/utils/get-check-option.js +26 -26
  429. package/lib/core/utils/get-flattened-tree.js +88 -88
  430. package/lib/core/utils/get-friendly-uri-end.js +87 -87
  431. package/lib/core/utils/get-node-attributes.js +9 -10
  432. package/lib/core/utils/get-node-from-tree.js +2 -2
  433. package/lib/core/utils/get-root-node.js +6 -6
  434. package/lib/core/utils/get-scroll-state.js +26 -26
  435. package/lib/core/utils/get-scroll.js +26 -26
  436. package/lib/core/utils/get-selector.js +256 -256
  437. package/lib/core/utils/get-shadow-selector.js +19 -19
  438. package/lib/core/utils/get-stylesheet-factory.js +32 -32
  439. package/lib/core/utils/get-xpath.js +65 -65
  440. package/lib/core/utils/index.js +3 -6
  441. package/lib/core/utils/inject-style.js +24 -24
  442. package/lib/core/utils/is-hidden.js +41 -41
  443. package/lib/core/utils/is-html-element.js +122 -122
  444. package/lib/core/utils/is-node-in-context.js +24 -24
  445. package/lib/core/utils/is-shadow-root.js +28 -28
  446. package/lib/core/utils/is-xhtml.js +4 -4
  447. package/lib/core/utils/matches.js +170 -176
  448. package/lib/core/utils/memoize.js +7 -7
  449. package/lib/core/utils/merge-results.js +91 -91
  450. package/lib/core/utils/node-sorter.js +11 -11
  451. package/lib/core/utils/parse-crossorigin-stylesheet.js +41 -41
  452. package/lib/core/utils/parse-sameorigin-stylesheet.js +70 -70
  453. package/lib/core/utils/parse-stylesheet.js +41 -41
  454. package/lib/core/utils/performance-timer.js +112 -112
  455. package/lib/core/utils/pollyfills.js +263 -263
  456. package/lib/core/utils/preload-cssom.js +134 -134
  457. package/lib/core/utils/preload-media.js +42 -42
  458. package/lib/core/utils/preload.js +110 -110
  459. package/lib/core/utils/process-message.js +43 -45
  460. package/lib/core/utils/publish-metadata.js +68 -68
  461. package/lib/core/utils/query-selector-all-filter.js +77 -79
  462. package/lib/core/utils/query-selector-all.js +1 -1
  463. package/lib/core/utils/queue.js +113 -113
  464. package/lib/core/utils/respondable.js +218 -119
  465. package/lib/core/utils/rule-should-run.js +53 -53
  466. package/lib/core/utils/select.js +54 -54
  467. package/lib/core/utils/send-command-to-frame.js +43 -43
  468. package/lib/core/utils/set-scroll-state.js +7 -7
  469. package/lib/core/utils/to-array.js +1 -1
  470. package/lib/core/utils/token-list.js +4 -4
  471. package/lib/core/utils/unique-array.js +3 -3
  472. package/lib/core/utils/uuid.js +161 -170
  473. package/lib/core/utils/valid-input-type.js +25 -25
  474. package/lib/core/utils/valid-langs.js +30 -30
  475. package/lib/misc/any-failure-summary.json +4 -4
  476. package/lib/misc/incomplete-fallback.json +1 -1
  477. package/lib/misc/none-failure-summary.json +4 -4
  478. package/lib/rules/accesskeys.json +11 -11
  479. package/lib/rules/area-alt.json +20 -20
  480. package/lib/rules/aria-allowed-attr-matches.js +13 -11
  481. package/lib/rules/aria-allowed-attr.json +10 -10
  482. package/lib/rules/aria-allowed-role-matches.js +6 -6
  483. package/lib/rules/aria-allowed-role.json +12 -12
  484. package/lib/rules/aria-command-name.json +16 -16
  485. package/lib/rules/aria-dialog-name.json +11 -11
  486. package/lib/rules/aria-has-attr-matches.js +10 -10
  487. package/lib/rules/aria-hidden-body.json +12 -12
  488. package/lib/rules/aria-hidden-focus-matches.js +8 -8
  489. package/lib/rules/aria-hidden-focus.json +16 -16
  490. package/lib/rules/aria-input-field-name.json +11 -11
  491. package/lib/rules/aria-meter-name.json +11 -11
  492. package/lib/rules/aria-progressbar-name.json +11 -11
  493. package/lib/rules/aria-required-attr.json +10 -10
  494. package/lib/rules/aria-required-children.json +10 -11
  495. package/lib/rules/aria-required-parent.json +10 -11
  496. package/lib/rules/aria-roledescription.json +10 -10
  497. package/lib/rules/aria-roles.json +11 -11
  498. package/lib/rules/aria-toggle-field-name.json +16 -16
  499. package/lib/rules/aria-tooltip-name.json +16 -16
  500. package/lib/rules/aria-treeitem-name.json +16 -16
  501. package/lib/rules/aria-valid-attr-value.json +10 -10
  502. package/lib/rules/aria-valid-attr.json +10 -10
  503. package/lib/rules/audio-caption.json +18 -18
  504. package/lib/rules/autocomplete-matches.js +50 -50
  505. package/lib/rules/autocomplete-valid.json +10 -10
  506. package/lib/rules/avoid-inline-spacing.json +10 -10
  507. package/lib/rules/blink.json +17 -17
  508. package/lib/rules/button-name.json +24 -24
  509. package/lib/rules/bypass-matches.js +7 -7
  510. package/lib/rules/bypass.json +18 -19
  511. package/lib/rules/color-contrast-matches.js +137 -145
  512. package/lib/rules/color-contrast.json +11 -11
  513. package/lib/rules/css-orientation-lock.json +11 -11
  514. package/lib/rules/data-table-large-matches.js +10 -10
  515. package/lib/rules/data-table-matches.js +1 -1
  516. package/lib/rules/definition-list.json +11 -11
  517. package/lib/rules/dlitem.json +11 -11
  518. package/lib/rules/document-title.json +11 -11
  519. package/lib/rules/duplicate-id-active-matches.js +6 -6
  520. package/lib/rules/duplicate-id-active.json +12 -12
  521. package/lib/rules/duplicate-id-aria-matches.js +1 -1
  522. package/lib/rules/duplicate-id-aria.json +12 -12
  523. package/lib/rules/duplicate-id-misc-matches.js +8 -8
  524. package/lib/rules/duplicate-id.json +12 -12
  525. package/lib/rules/empty-heading.json +17 -17
  526. package/lib/rules/focus-order-semantics.json +11 -11
  527. package/lib/rules/form-field-multiple-labels.json +11 -11
  528. package/lib/rules/frame-tested.json +10 -10
  529. package/lib/rules/frame-title-has-text-matches.js +2 -2
  530. package/lib/rules/frame-title-unique.json +11 -11
  531. package/lib/rules/frame-title.json +22 -22
  532. package/lib/rules/heading-matches.js +14 -14
  533. package/lib/rules/heading-order.json +11 -11
  534. package/lib/rules/hidden-content.json +11 -11
  535. package/lib/rules/html-has-lang.json +11 -11
  536. package/lib/rules/html-lang-valid.json +10 -10
  537. package/lib/rules/html-namespace-matches.js +1 -1
  538. package/lib/rules/html-xml-lang-mismatch.json +11 -11
  539. package/lib/rules/identical-links-same-purpose-matches.js +9 -9
  540. package/lib/rules/identical-links-same-purpose.json +12 -12
  541. package/lib/rules/image-alt.json +24 -24
  542. package/lib/rules/img-redundant-alt.json +10 -10
  543. package/lib/rules/input-button-name.json +24 -24
  544. package/lib/rules/input-image-alt.json +18 -18
  545. package/lib/rules/inserted-into-focus-order-matches.js +1 -1
  546. package/lib/rules/is-initiator-matches.js +1 -1
  547. package/lib/rules/label-content-name-mismatch-matches.js +38 -38
  548. package/lib/rules/label-content-name-mismatch.json +10 -10
  549. package/lib/rules/label-matches.js +10 -10
  550. package/lib/rules/label-title-only.json +11 -11
  551. package/lib/rules/label.json +27 -27
  552. package/lib/rules/landmark-banner-is-top-level.json +11 -11
  553. package/lib/rules/landmark-complementary-is-top-level.json +10 -10
  554. package/lib/rules/landmark-contentinfo-is-top-level.json +11 -11
  555. package/lib/rules/landmark-has-body-context-matches.js +6 -6
  556. package/lib/rules/landmark-main-is-top-level.json +10 -10
  557. package/lib/rules/landmark-no-duplicate-banner.json +10 -10
  558. package/lib/rules/landmark-no-duplicate-contentinfo.json +10 -10
  559. package/lib/rules/landmark-no-duplicate-main.json +10 -10
  560. package/lib/rules/landmark-one-main.json +10 -10
  561. package/lib/rules/landmark-unique-matches.js +36 -36
  562. package/lib/rules/landmark-unique.json +11 -11
  563. package/lib/rules/layout-table-matches.js +2 -1
  564. package/lib/rules/link-in-text-block-matches.js +12 -12
  565. package/lib/rules/link-in-text-block.json +12 -12
  566. package/lib/rules/link-name.json +23 -23
  567. package/lib/rules/list.json +11 -11
  568. package/lib/rules/listitem.json +11 -11
  569. package/lib/rules/marquee.json +11 -11
  570. package/lib/rules/meta-refresh.json +18 -18
  571. package/lib/rules/meta-viewport-large.json +11 -11
  572. package/lib/rules/meta-viewport.json +11 -11
  573. package/lib/rules/no-autoplay-audio-matches.js +16 -16
  574. package/lib/rules/no-autoplay-audio.json +13 -13
  575. package/lib/rules/no-empty-role-matches.js +7 -7
  576. package/lib/rules/no-explicit-name-required-matches.js +9 -9
  577. package/lib/rules/no-naming-method-matches.js +12 -12
  578. package/lib/rules/no-role-matches.js +1 -1
  579. package/lib/rules/not-html-matches.js +2 -2
  580. package/lib/rules/object-alt.json +22 -22
  581. package/lib/rules/p-as-heading-matches.js +14 -14
  582. package/lib/rules/p-as-heading.json +11 -11
  583. package/lib/rules/page-has-heading-one.json +10 -10
  584. package/lib/rules/presentation-role-conflict.json +10 -10
  585. package/lib/rules/region.json +10 -10
  586. package/lib/rules/role-img-alt.json +18 -18
  587. package/lib/rules/scope-attr-valid.json +10 -10
  588. package/lib/rules/scrollable-region-focusable-matches.js +59 -59
  589. package/lib/rules/scrollable-region-focusable.json +10 -10
  590. package/lib/rules/select-name.json +25 -25
  591. package/lib/rules/server-side-image-map.json +16 -16
  592. package/lib/rules/skip-link-matches.js +1 -1
  593. package/lib/rules/skip-link.json +11 -11
  594. package/lib/rules/svg-img-alt.json +23 -23
  595. package/lib/rules/svg-namespace-matches.js +10 -10
  596. package/lib/rules/tabindex.json +10 -10
  597. package/lib/rules/table-duplicate-name.json +10 -10
  598. package/lib/rules/table-fake-caption.json +18 -18
  599. package/lib/rules/td-has-header.json +18 -18
  600. package/lib/rules/td-headers-attr.json +10 -10
  601. package/lib/rules/th-has-data-cells.json +11 -11
  602. package/lib/rules/valid-lang.json +11 -11
  603. package/lib/rules/video-caption.json +17 -17
  604. package/lib/rules/window-is-top-matches.js +3 -3
  605. package/lib/rules/xml-lang-mismatch-matches.js +6 -6
  606. package/lib/standards/aria-attrs.js +195 -204
  607. package/lib/standards/aria-roles.js +781 -812
  608. package/lib/standards/css-colors.js +148 -148
  609. package/lib/standards/dpub-roles.js +213 -214
  610. package/lib/standards/html-elms.js +912 -914
  611. package/lib/standards/index.js +16 -18
  612. package/locales/de.json +572 -909
  613. package/package.json +151 -174
  614. package/sri-history.json +1 -5
  615. package/typings/axe-core/axe-core-tests.ts +144 -144
  616. package/.eslintrc.js +0 -111
  617. package/lib/checks/aria/aria-prohibited-attr-evaluate.js +0 -67
  618. package/lib/checks/aria/aria-prohibited-attr.json +0 -12
  619. package/lib/checks/keyboard/frame-focusable-content.json +0 -12
  620. package/lib/checks/keyboard/no-focusable-content-evaluate.js +0 -35
  621. package/lib/checks/keyboard/no-focusable-content.json +0 -12
  622. package/lib/core/public/setup.js +0 -20
  623. package/lib/core/public/teardown.js +0 -21
  624. package/lib/core/utils/filter-html-attrs.js +0 -75
  625. package/lib/core/utils/get-rule.js +0 -17
  626. package/lib/core/utils/respondable/assert-window.js +0 -21
  627. package/lib/core/utils/respondable/callback-store.js +0 -36
  628. package/lib/core/utils/respondable/message-id.js +0 -22
  629. package/lib/core/utils/respondable/message-parser.js +0 -109
  630. package/lib/core/utils/respondable/post.js +0 -32
  631. package/lib/rules/aria-required-children-matches.js +0 -8
  632. package/lib/rules/aria-required-parent-matches.js +0 -8
  633. package/lib/rules/aria-text.json +0 -12
  634. package/lib/rules/empty-table-header.json +0 -13
  635. package/lib/rules/frame-focusable-content-matches.js +0 -9
  636. package/lib/rules/frame-focusable-content.json +0 -13
  637. package/lib/rules/nested-interactive-matches.js +0 -13
  638. package/lib/rules/nested-interactive.json +0 -12
  639. package/lib/standards/graphics-roles.js +0 -22
  640. package/locales/pl.json +0 -911
@@ -3,12 +3,12 @@ import Check from './check';
3
3
  import standards from '../../standards';
4
4
  import RuleResult from './rule-result';
5
5
  import {
6
- clone,
7
- queue,
8
- preload,
9
- findBy,
10
- ruleShouldRun,
11
- performanceTimer
6
+ clone,
7
+ queue,
8
+ preload,
9
+ findBy,
10
+ ruleShouldRun,
11
+ performanceTimer
12
12
  } from '../utils';
13
13
  import doT from '@deque/dot';
14
14
  import log from '../log';
@@ -18,30 +18,30 @@ const dotRegex = /\{\{.+?\}\}/g;
18
18
 
19
19
  /*eslint no-unused-vars: 0*/
20
20
  function getDefaultConfiguration(audit) {
21
- var config;
22
- if (audit) {
23
- config = clone(audit);
24
- // Commons are configured into axe like everything else,
25
- // however because things go funky if we have multiple commons objects
26
- // we're not using the copy of that.
27
- config.commons = audit.commons;
28
- } else {
29
- config = {};
30
- }
21
+ var config;
22
+ if (audit) {
23
+ config = clone(audit);
24
+ // Commons are configured into axe like everything else,
25
+ // however because things go funky if we have multiple commons objects
26
+ // we're not using the copy of that.
27
+ config.commons = audit.commons;
28
+ } else {
29
+ config = {};
30
+ }
31
31
 
32
- config.reporter = config.reporter || null;
33
- config.noHtml = config.noHtml || false;
34
- config.rules = config.rules || [];
35
- config.checks = config.checks || [];
36
- config.data = { checks: {}, rules: {}, ...config.data };
37
- return config;
32
+ config.reporter = config.reporter || null;
33
+ config.noHtml = config.noHtml || false;
34
+ config.rules = config.rules || [];
35
+ config.checks = config.checks || [];
36
+ config.data = { checks: {}, rules: {}, ...config.data };
37
+ return config;
38
38
  }
39
39
 
40
40
  function unpackToObject(collection, audit, method) {
41
- var i, l;
42
- for (i = 0, l = collection.length; i < l; i++) {
43
- audit[method](collection[i]);
44
- }
41
+ var i, l;
42
+ for (i = 0, l = collection.length; i < l; i++) {
43
+ audit[method](collection[i]);
44
+ }
45
45
  }
46
46
 
47
47
  /**
@@ -70,30 +70,30 @@ function unpackToObject(collection, audit, method) {
70
70
  */
71
71
 
72
72
  const mergeCheckLocale = (a, b) => {
73
- let { pass, fail } = b;
74
- // If the message(s) are Strings, they have not yet been run
75
- // thru doT (which will return a Function).
76
- if (typeof pass === 'string' && dotRegex.test(pass)) {
77
- pass = doT.compile(pass);
78
- }
79
- if (typeof fail === 'string' && dotRegex.test(fail)) {
80
- fail = doT.compile(fail);
81
- }
82
- return {
83
- ...a,
84
- messages: {
85
- pass: pass || a.messages.pass,
86
- fail: fail || a.messages.fail,
87
- incomplete:
88
- typeof a.messages.incomplete === 'object'
89
- ? // TODO: for compleness-sake, we should be running
90
- // incomplete messages thru doT as well. This was
91
- // out-of-scope for runtime localization, but should
92
- // eventually be addressed.
93
- { ...a.messages.incomplete, ...b.incomplete }
94
- : b.incomplete
95
- }
96
- };
73
+ let { pass, fail } = b;
74
+ // If the message(s) are Strings, they have not yet been run
75
+ // thru doT (which will return a Function).
76
+ if (typeof pass === 'string' && dotRegex.test(pass)) {
77
+ pass = doT.compile(pass);
78
+ }
79
+ if (typeof fail === 'string' && dotRegex.test(fail)) {
80
+ fail = doT.compile(fail);
81
+ }
82
+ return {
83
+ ...a,
84
+ messages: {
85
+ pass: pass || a.messages.pass,
86
+ fail: fail || a.messages.fail,
87
+ incomplete:
88
+ typeof a.messages.incomplete === 'object'
89
+ ? // TODO: for compleness-sake, we should be running
90
+ // incomplete messages thru doT as well. This was
91
+ // out-of-scope for runtime localization, but should
92
+ // eventually be addressed.
93
+ { ...a.messages.incomplete, ...b.incomplete }
94
+ : b.incomplete
95
+ }
96
+ };
97
97
  };
98
98
 
99
99
  /**
@@ -101,20 +101,20 @@ const mergeCheckLocale = (a, b) => {
101
101
  */
102
102
 
103
103
  const mergeRuleLocale = (a, b) => {
104
- let { help, description } = b;
105
- // If the message(s) are Strings, they have not yet been run
106
- // thru doT (which will return a Function).
107
- if (typeof help === 'string' && dotRegex.test(help)) {
108
- help = doT.compile(help);
109
- }
110
- if (typeof description === 'string' && dotRegex.test(description)) {
111
- description = doT.compile(description);
112
- }
113
- return {
114
- ...a,
115
- help: help || a.help,
116
- description: description || a.description
117
- };
104
+ let { help, description } = b;
105
+ // If the message(s) are Strings, they have not yet been run
106
+ // thru doT (which will return a Function).
107
+ if (typeof help === 'string' && dotRegex.test(help)) {
108
+ help = doT.compile(help);
109
+ }
110
+ if (typeof description === 'string' && dotRegex.test(description)) {
111
+ description = doT.compile(description);
112
+ }
113
+ return {
114
+ ...a,
115
+ help: help || a.help,
116
+ description: description || a.description
117
+ };
118
118
  };
119
119
 
120
120
  /**
@@ -122,16 +122,16 @@ const mergeRuleLocale = (a, b) => {
122
122
  */
123
123
 
124
124
  const mergeFailureMessage = (a, b) => {
125
- let { failureMessage } = b;
126
- // If the message(s) are Strings, they have not yet been run
127
- // thru doT (which will return a Function).
128
- if (typeof failureMessage === 'string' && dotRegex.test(failureMessage)) {
129
- failureMessage = doT.compile(failureMessage);
130
- }
131
- return {
132
- ...a,
133
- failureMessage: failureMessage || a.failureMessage
134
- };
125
+ let { failureMessage } = b;
126
+ // If the message(s) are Strings, they have not yet been run
127
+ // thru doT (which will return a Function).
128
+ if (typeof failureMessage === 'string' && dotRegex.test(failureMessage)) {
129
+ failureMessage = doT.compile(failureMessage);
130
+ }
131
+ return {
132
+ ...a,
133
+ failureMessage: failureMessage || a.failureMessage
134
+ };
135
135
  };
136
136
 
137
137
  /**
@@ -139,482 +139,482 @@ const mergeFailureMessage = (a, b) => {
139
139
  */
140
140
 
141
141
  const mergeFallbackMessage = (a, b) => {
142
- if (typeof b === 'string' && dotRegex.test(b)) {
143
- b = doT.compile(b);
144
- }
145
- return b || a;
142
+ if (typeof b === 'string' && dotRegex.test(b)) {
143
+ b = doT.compile(b);
144
+ }
145
+ return b || a;
146
146
  };
147
147
 
148
148
  /**
149
149
  * Constructor which holds configured rules and information about the document under test
150
150
  */
151
151
  class Audit {
152
- constructor(audit) {
153
- // defaults
154
- this.lang = 'en';
155
- this.defaultConfig = audit;
156
- this.standards = standards;
157
- this._init();
158
- // A copy of the "default" locale. This will be set if the user
159
- // provides a new locale to `axe.configure()` and used to undo
160
- // changes in `axe.reset()`.
161
- this._defaultLocale = null;
162
- }
163
- /**
164
- * Build and set the previous locale. Will noop if a previous
165
- * locale was already set, as we want the ability to "reset"
166
- * to the default ("first") configuration.
167
- */
168
- _setDefaultLocale() {
169
- if (this._defaultLocale) {
170
- return;
171
- }
172
- const locale = {
173
- checks: {},
174
- rules: {},
175
- failureSummaries: {},
176
- incompleteFallbackMessage: '',
177
- lang: this.lang
178
- };
179
- // XXX: unable to use `for-of` here, as doing so would
180
- // require us to polyfill `Symbol`.
181
- const checkIDs = Object.keys(this.data.checks);
182
- for (let i = 0; i < checkIDs.length; i++) {
183
- const id = checkIDs[i];
184
- const check = this.data.checks[id];
185
- const { pass, fail, incomplete } = check.messages;
186
- locale.checks[id] = {
187
- pass,
188
- fail,
189
- incomplete
190
- };
191
- }
192
- const ruleIDs = Object.keys(this.data.rules);
193
- for (let i = 0; i < ruleIDs.length; i++) {
194
- const id = ruleIDs[i];
195
- const rule = this.data.rules[id];
196
- const { description, help } = rule;
197
- locale.rules[id] = { description, help };
198
- }
199
- const failureSummaries = Object.keys(this.data.failureSummaries);
200
- for (let i = 0; i < failureSummaries.length; i++) {
201
- const type = failureSummaries[i];
202
- const failureSummary = this.data.failureSummaries[type];
203
- const { failureMessage } = failureSummary;
204
- locale.failureSummaries[type] = { failureMessage };
205
- }
206
- locale.incompleteFallbackMessage = this.data.incompleteFallbackMessage;
207
- this._defaultLocale = locale;
208
- }
209
- /**
210
- * Reset the locale to the "default".
211
- */
212
- _resetLocale() {
213
- // If the default locale has not already been set, we can exit early.
214
- const defaultLocale = this._defaultLocale;
215
- if (!defaultLocale) {
216
- return;
217
- }
218
- // Apply the default locale
219
- this.applyLocale(defaultLocale);
220
- }
221
- /**
222
- * Apply locale for the given `checks`.
223
- */
224
- _applyCheckLocale(checks) {
225
- const keys = Object.keys(checks);
226
- for (let i = 0; i < keys.length; i++) {
227
- const id = keys[i];
228
- if (!this.data.checks[id]) {
229
- throw new Error(`Locale provided for unknown check: "${id}"`);
230
- }
231
- this.data.checks[id] = mergeCheckLocale(this.data.checks[id], checks[id]);
232
- }
233
- }
234
- /**
235
- * Apply locale for the given `rules`.
236
- */
237
- _applyRuleLocale(rules) {
238
- const keys = Object.keys(rules);
239
- for (let i = 0; i < keys.length; i++) {
240
- const id = keys[i];
241
- if (!this.data.rules[id]) {
242
- throw new Error(`Locale provided for unknown rule: "${id}"`);
243
- }
244
- this.data.rules[id] = mergeRuleLocale(this.data.rules[id], rules[id]);
245
- }
246
- }
247
- /**
248
- * Apply locale for the given failureMessage
249
- */
250
- _applyFailureSummaries(messages) {
251
- const keys = Object.keys(messages);
252
- for (let i = 0; i < keys.length; i++) {
253
- const key = keys[i];
254
- if (!this.data.failureSummaries[key]) {
255
- throw new Error(`Locale provided for unknown failureMessage: "${key}"`);
256
- }
257
- this.data.failureSummaries[key] = mergeFailureMessage(
258
- this.data.failureSummaries[key],
259
- messages[key]
260
- );
261
- }
262
- }
263
- /**
264
- * Apply the given `locale`.
265
- *
266
- * @param {axe.Locale}
267
- */
268
- applyLocale(locale) {
269
- this._setDefaultLocale();
270
- if (locale.checks) {
271
- this._applyCheckLocale(locale.checks);
272
- }
273
- if (locale.rules) {
274
- this._applyRuleLocale(locale.rules);
275
- }
276
- if (locale.failureSummaries) {
277
- this._applyFailureSummaries(locale.failureSummaries, 'failureSummaries');
278
- }
279
- if (locale.incompleteFallbackMessage) {
280
- this.data.incompleteFallbackMessage = mergeFallbackMessage(
281
- this.data.incompleteFallbackMessage,
282
- locale.incompleteFallbackMessage
283
- );
284
- }
285
- if (locale.lang) {
286
- this.lang = locale.lang;
287
- }
288
- }
289
- /**
290
- * Initializes the rules and checks
291
- */
292
- _init() {
293
- var audit = getDefaultConfiguration(this.defaultConfig);
294
- this.lang = audit.lang || 'en';
295
- this.reporter = audit.reporter;
296
- this.commands = {};
297
- this.rules = [];
298
- this.checks = {};
299
- this.brand = 'axe';
300
- this.application = 'axeAPI';
301
- this.tagExclude = ['experimental'];
302
- this.noHtml = audit.noHtml;
303
- unpackToObject(audit.rules, this, 'addRule');
304
- unpackToObject(audit.checks, this, 'addCheck');
305
- this.data = {};
306
- this.data.checks = (audit.data && audit.data.checks) || {};
307
- this.data.rules = (audit.data && audit.data.rules) || {};
308
- this.data.failureSummaries =
309
- (audit.data && audit.data.failureSummaries) || {};
310
- this.data.incompleteFallbackMessage =
311
- (audit.data && audit.data.incompleteFallbackMessage) || '';
312
- this._constructHelpUrls(); // create default helpUrls
313
- }
314
- /**
315
- * Adds a new command to the audit
316
- */
317
- registerCommand(command) {
318
- this.commands[command.id] = command.callback;
319
- }
320
- /**
321
- * Adds a new rule to the Audit. If a rule with specified ID already exists, it will be overridden
322
- * @param {Object} spec Rule specification object
323
- */
324
- addRule(spec) {
325
- if (spec.metadata) {
326
- this.data.rules[spec.id] = spec.metadata;
327
- }
328
- const rule = this.getRule(spec.id);
329
- if (rule) {
330
- rule.configure(spec);
331
- } else {
332
- this.rules.push(new Rule(spec, this));
333
- }
334
- }
335
- /**
336
- * Adds a new check to the Audit. If a Check with specified ID already exists, it will be
337
- * reconfigured
338
- *
339
- * @param {Object} spec Check specification object
340
- */
341
- addCheck(spec) {
342
- /*eslint no-eval: 0 */
152
+ constructor(audit) {
153
+ // defaults
154
+ this.lang = 'en';
155
+ this.defaultConfig = audit;
156
+ this.standards = standards;
157
+ this._init();
158
+ // A copy of the "default" locale. This will be set if the user
159
+ // provides a new locale to `axe.configure()` and used to undo
160
+ // changes in `axe.reset()`.
161
+ this._defaultLocale = null;
162
+ }
163
+ /**
164
+ * Build and set the previous locale. Will noop if a previous
165
+ * locale was already set, as we want the ability to "reset"
166
+ * to the default ("first") configuration.
167
+ */
168
+ _setDefaultLocale() {
169
+ if (this._defaultLocale) {
170
+ return;
171
+ }
172
+ const locale = {
173
+ checks: {},
174
+ rules: {},
175
+ failureSummaries: {},
176
+ incompleteFallbackMessage: '',
177
+ lang: this.lang
178
+ };
179
+ // XXX: unable to use `for-of` here, as doing so would
180
+ // require us to polyfill `Symbol`.
181
+ const checkIDs = Object.keys(this.data.checks);
182
+ for (let i = 0; i < checkIDs.length; i++) {
183
+ const id = checkIDs[i];
184
+ const check = this.data.checks[id];
185
+ const { pass, fail, incomplete } = check.messages;
186
+ locale.checks[id] = {
187
+ pass,
188
+ fail,
189
+ incomplete
190
+ };
191
+ }
192
+ const ruleIDs = Object.keys(this.data.rules);
193
+ for (let i = 0; i < ruleIDs.length; i++) {
194
+ const id = ruleIDs[i];
195
+ const rule = this.data.rules[id];
196
+ const { description, help } = rule;
197
+ locale.rules[id] = { description, help };
198
+ }
199
+ const failureSummaries = Object.keys(this.data.failureSummaries);
200
+ for (let i = 0; i < failureSummaries.length; i++) {
201
+ const type = failureSummaries[i];
202
+ const failureSummary = this.data.failureSummaries[type];
203
+ const { failureMessage } = failureSummary;
204
+ locale.failureSummaries[type] = { failureMessage };
205
+ }
206
+ locale.incompleteFallbackMessage = this.data.incompleteFallbackMessage;
207
+ this._defaultLocale = locale;
208
+ }
209
+ /**
210
+ * Reset the locale to the "default".
211
+ */
212
+ _resetLocale() {
213
+ // If the default locale has not already been set, we can exit early.
214
+ const defaultLocale = this._defaultLocale;
215
+ if (!defaultLocale) {
216
+ return;
217
+ }
218
+ // Apply the default locale
219
+ this.applyLocale(defaultLocale);
220
+ }
221
+ /**
222
+ * Apply locale for the given `checks`.
223
+ */
224
+ _applyCheckLocale(checks) {
225
+ const keys = Object.keys(checks);
226
+ for (let i = 0; i < keys.length; i++) {
227
+ const id = keys[i];
228
+ if (!this.data.checks[id]) {
229
+ throw new Error(`Locale provided for unknown check: "${id}"`);
230
+ }
231
+ this.data.checks[id] = mergeCheckLocale(this.data.checks[id], checks[id]);
232
+ }
233
+ }
234
+ /**
235
+ * Apply locale for the given `rules`.
236
+ */
237
+ _applyRuleLocale(rules) {
238
+ const keys = Object.keys(rules);
239
+ for (let i = 0; i < keys.length; i++) {
240
+ const id = keys[i];
241
+ if (!this.data.rules[id]) {
242
+ throw new Error(`Locale provided for unknown rule: "${id}"`);
243
+ }
244
+ this.data.rules[id] = mergeRuleLocale(this.data.rules[id], rules[id]);
245
+ }
246
+ }
247
+ /**
248
+ * Apply locale for the given failureMessage
249
+ */
250
+ _applyFailureSummaries(messages) {
251
+ const keys = Object.keys(messages);
252
+ for (let i = 0; i < keys.length; i++) {
253
+ const key = keys[i];
254
+ if (!this.data.failureSummaries[key]) {
255
+ throw new Error(`Locale provided for unknown failureMessage: "${key}"`);
256
+ }
257
+ this.data.failureSummaries[key] = mergeFailureMessage(
258
+ this.data.failureSummaries[key],
259
+ messages[key]
260
+ );
261
+ }
262
+ }
263
+ /**
264
+ * Apply the given `locale`.
265
+ *
266
+ * @param {axe.Locale}
267
+ */
268
+ applyLocale(locale) {
269
+ this._setDefaultLocale();
270
+ if (locale.checks) {
271
+ this._applyCheckLocale(locale.checks);
272
+ }
273
+ if (locale.rules) {
274
+ this._applyRuleLocale(locale.rules);
275
+ }
276
+ if (locale.failureSummaries) {
277
+ this._applyFailureSummaries(locale.failureSummaries, 'failureSummaries');
278
+ }
279
+ if (locale.incompleteFallbackMessage) {
280
+ this.data.incompleteFallbackMessage = mergeFallbackMessage(
281
+ this.data.incompleteFallbackMessage,
282
+ locale.incompleteFallbackMessage
283
+ );
284
+ }
285
+ if (locale.lang) {
286
+ this.lang = locale.lang;
287
+ }
288
+ }
289
+ /**
290
+ * Initializes the rules and checks
291
+ */
292
+ _init() {
293
+ var audit = getDefaultConfiguration(this.defaultConfig);
294
+ this.lang = audit.lang || 'en';
295
+ this.reporter = audit.reporter;
296
+ this.commands = {};
297
+ this.rules = [];
298
+ this.checks = {};
299
+ this.brand = 'axe';
300
+ this.application = 'axeAPI';
301
+ this.tagExclude = ['experimental'];
302
+ this.noHtml = audit.noHtml;
303
+ unpackToObject(audit.rules, this, 'addRule');
304
+ unpackToObject(audit.checks, this, 'addCheck');
305
+ this.data = {};
306
+ this.data.checks = (audit.data && audit.data.checks) || {};
307
+ this.data.rules = (audit.data && audit.data.rules) || {};
308
+ this.data.failureSummaries =
309
+ (audit.data && audit.data.failureSummaries) || {};
310
+ this.data.incompleteFallbackMessage =
311
+ (audit.data && audit.data.incompleteFallbackMessage) || '';
312
+ this._constructHelpUrls(); // create default helpUrls
313
+ }
314
+ /**
315
+ * Adds a new command to the audit
316
+ */
317
+ registerCommand(command) {
318
+ this.commands[command.id] = command.callback;
319
+ }
320
+ /**
321
+ * Adds a new rule to the Audit. If a rule with specified ID already exists, it will be overridden
322
+ * @param {Object} spec Rule specification object
323
+ */
324
+ addRule(spec) {
325
+ if (spec.metadata) {
326
+ this.data.rules[spec.id] = spec.metadata;
327
+ }
328
+ const rule = this.getRule(spec.id);
329
+ if (rule) {
330
+ rule.configure(spec);
331
+ } else {
332
+ this.rules.push(new Rule(spec, this));
333
+ }
334
+ }
335
+ /**
336
+ * Adds a new check to the Audit. If a Check with specified ID already exists, it will be
337
+ * reconfigured
338
+ *
339
+ * @param {Object} spec Check specification object
340
+ */
341
+ addCheck(spec) {
342
+ /*eslint no-eval: 0 */
343
343
 
344
- const metadata = spec.metadata;
345
- if (typeof metadata === 'object') {
346
- this.data.checks[spec.id] = metadata;
347
- // Transform messages into functions:
348
- if (typeof metadata.messages === 'object') {
349
- Object.keys(metadata.messages)
350
- .filter(
351
- prop =>
352
- metadata.messages.hasOwnProperty(prop) &&
353
- typeof metadata.messages[prop] === 'string'
354
- )
355
- .forEach(prop => {
356
- if (metadata.messages[prop].indexOf('function') === 0) {
357
- metadata.messages[prop] = new Function(
358
- 'return ' + metadata.messages[prop] + ';'
359
- )();
360
- }
361
- });
362
- }
363
- }
364
- if (this.checks[spec.id]) {
365
- this.checks[spec.id].configure(spec);
366
- } else {
367
- this.checks[spec.id] = new Check(spec);
368
- }
369
- }
370
- /**
371
- * Runs the Audit; which in turn should call `run` on each rule.
372
- * @async
373
- * @param {Context} context The scope definition/context for analysis (include/exclude)
374
- * @param {Object} options Options object to pass into rules and/or disable rules or checks
375
- * @param {Function} fn Callback function to fire when audit is complete
376
- */
377
- run(context, options, resolve, reject) {
378
- this.normalizeOptions(options);
344
+ let metadata = spec.metadata;
345
+ if (typeof metadata === 'object') {
346
+ this.data.checks[spec.id] = metadata;
347
+ // Transform messages into functions:
348
+ if (typeof metadata.messages === 'object') {
349
+ Object.keys(metadata.messages)
350
+ .filter(
351
+ prop =>
352
+ metadata.messages.hasOwnProperty(prop) &&
353
+ typeof metadata.messages[prop] === 'string'
354
+ )
355
+ .forEach(prop => {
356
+ if (metadata.messages[prop].indexOf('function') === 0) {
357
+ metadata.messages[prop] = new Function(
358
+ 'return ' + metadata.messages[prop] + ';'
359
+ )();
360
+ }
361
+ });
362
+ }
363
+ }
364
+ if (this.checks[spec.id]) {
365
+ this.checks[spec.id].configure(spec);
366
+ } else {
367
+ this.checks[spec.id] = new Check(spec);
368
+ }
369
+ }
370
+ /**
371
+ * Runs the Audit; which in turn should call `run` on each rule.
372
+ * @async
373
+ * @param {Context} context The scope definition/context for analysis (include/exclude)
374
+ * @param {Object} options Options object to pass into rules and/or disable rules or checks
375
+ * @param {Function} fn Callback function to fire when audit is complete
376
+ */
377
+ run(context, options, resolve, reject) {
378
+ this.normalizeOptions(options);
379
379
 
380
- // TODO: es-modules_selectCache
381
- axe._selectCache = [];
382
- // get a list of rules to run NOW vs. LATER (later are preload assets dependent rules)
383
- const allRulesToRun = getRulesToRun(this.rules, context, options);
384
- const runNowRules = allRulesToRun.now;
385
- const runLaterRules = allRulesToRun.later;
386
- // init a NOW queue for rules to run immediately
387
- const nowRulesQueue = queue();
388
- // construct can run NOW rules into NOW queue
389
- runNowRules.forEach(rule => {
390
- nowRulesQueue.defer(getDefferedRule(rule, context, options));
391
- });
392
- // init a PRELOADER queue to start preloading assets
393
- const preloaderQueue = queue();
394
- // defer preload if preload dependent rules exist
395
- if (runLaterRules.length) {
396
- preloaderQueue.defer(resolve => {
397
- // handle both success and fail of preload
398
- // and resolve, to allow to run all checks
399
- preload(options)
400
- .then(assets => resolve(assets))
401
- .catch(err => {
402
- /**
403
- * Note:
404
- * we do not reject, to allow other (non-preload) rules to `run`
405
- * -> instead we resolve as `undefined`
406
- */
407
- console.warn(`Couldn't load preload assets: `, err);
408
- resolve(undefined);
409
- });
410
- });
411
- }
412
- // defer now and preload queue to run immediately
413
- const queueForNowRulesAndPreloader = queue();
414
- queueForNowRulesAndPreloader.defer(nowRulesQueue);
415
- queueForNowRulesAndPreloader.defer(preloaderQueue);
416
- // invoke the now queue
417
- queueForNowRulesAndPreloader
418
- .then(nowRulesAndPreloaderResults => {
419
- // interpolate results into separate variables
420
- const assetsFromQueue = nowRulesAndPreloaderResults.pop();
421
- if (assetsFromQueue && assetsFromQueue.length) {
422
- // result is a queue (again), hence the index resolution
423
- // assets is either an object of key value pairs of asset type and values
424
- // eg: cssom: [stylesheets]
425
- // or undefined if preload failed
426
- const assets = assetsFromQueue[0];
427
- // extend context with preloaded assets
428
- if (assets) {
429
- context = {
430
- ...context,
431
- ...assets
432
- };
433
- }
434
- }
435
- // the reminder of the results are RuleResults
436
- const nowRulesResults = nowRulesAndPreloaderResults[0];
437
- // if there are no rules to run LATER - resolve with rule results
438
- if (!runLaterRules.length) {
439
- // remove the cache
440
- axe._selectCache = undefined;
441
- // resolve
442
- resolve(nowRulesResults.filter(result => !!result));
443
- return;
444
- }
445
- // init a LATER queue for rules that are dependant on preloaded assets
446
- const laterRulesQueue = queue();
447
- runLaterRules.forEach(rule => {
448
- const deferredRule = getDefferedRule(rule, context, options);
449
- laterRulesQueue.defer(deferredRule);
450
- });
451
- // invoke the later queue
452
- laterRulesQueue
453
- .then(laterRuleResults => {
454
- // remove the cache
455
- axe._selectCache = undefined;
456
- // resolve
457
- resolve(
458
- nowRulesResults
459
- .concat(laterRuleResults)
460
- .filter(result => !!result)
461
- );
462
- })
463
- .catch(reject);
464
- })
465
- .catch(reject);
466
- }
467
- /**
468
- * Runs Rule `after` post processing functions
469
- * @param {Array} results Array of RuleResults to postprocess
470
- * @param {Mixed} options Options object to pass into rules and/or disable rules or checks
471
- */
472
- after(results, options) {
473
- var rules = this.rules;
474
- return results.map(ruleResult => {
475
- var rule = findBy(rules, 'id', ruleResult.id);
476
- if (!rule) {
477
- // If you see this, you're probably running the Mocha tests with the axe extension installed
478
- throw new Error(
479
- 'Result for unknown rule. You may be running mismatch axe-core versions'
480
- );
481
- }
482
- return rule.after(ruleResult, options);
483
- });
484
- }
485
- /**
486
- * Get the rule with a given ID
487
- * @param {string}
488
- * @return {Rule}
489
- */
490
- getRule(ruleId) {
491
- return this.rules.find(rule => rule.id === ruleId);
492
- }
493
- /**
494
- * Ensure all rules that are expected to run exist
495
- * @throws {Error} If any tag or rule specified in options is unknown
496
- * @param {Object} options Options object
497
- * @return {Object} Validated options object
498
- */
499
- normalizeOptions(options) {
500
- var audit = this;
501
- const tags = [];
502
- const ruleIds = [];
503
- audit.rules.forEach(rule => {
504
- ruleIds.push(rule.id);
505
- rule.tags.forEach(tag => {
506
- if (!tags.includes(tag)) {
507
- tags.push(tag);
508
- }
509
- });
510
- });
511
- // Validate runOnly
512
- if (typeof options.runOnly === 'object') {
513
- if (Array.isArray(options.runOnly)) {
514
- const hasTag = options.runOnly.find(value => tags.includes(value));
515
- const hasRule = options.runOnly.find(value => ruleIds.includes(value));
516
- if (hasTag && hasRule) {
517
- throw new Error('runOnly cannot be both rules and tags');
518
- }
519
- if (hasRule) {
520
- options.runOnly = {
521
- type: 'rule',
522
- values: options.runOnly
523
- };
524
- } else {
525
- options.runOnly = {
526
- type: 'tag',
527
- values: options.runOnly
528
- };
529
- }
530
- }
531
- const only = options.runOnly;
532
- if (only.value && !only.values) {
533
- only.values = only.value;
534
- delete only.value;
535
- }
536
- if (!Array.isArray(only.values) || only.values.length === 0) {
537
- throw new Error('runOnly.values must be a non-empty array');
538
- }
539
- // Check if every value in options.runOnly is a known rule ID
540
- if (['rule', 'rules'].includes(only.type)) {
541
- only.type = 'rule';
542
- only.values.forEach(ruleId => {
543
- if (!ruleIds.includes(ruleId)) {
544
- throw new Error('unknown rule `' + ruleId + '` in options.runOnly');
545
- }
546
- });
547
- // Validate 'tags' (e.g. anything not 'rule')
548
- } else if (['tag', 'tags', undefined].includes(only.type)) {
549
- only.type = 'tag';
550
- const unmatchedTags = only.values.filter(tag => !tags.includes(tag));
551
- if (unmatchedTags.length !== 0) {
552
- log('Could not find tags `' + unmatchedTags.join('`, `') + '`');
553
- }
554
- } else {
555
- throw new Error(`Unknown runOnly type '${only.type}'`);
556
- }
557
- }
558
- if (typeof options.rules === 'object') {
559
- Object.keys(options.rules).forEach(ruleId => {
560
- if (!ruleIds.includes(ruleId)) {
561
- throw new Error('unknown rule `' + ruleId + '` in options.rules');
562
- }
563
- });
564
- }
565
- return options;
566
- }
567
- /*
568
- * Updates the default options and then applies them
569
- * @param {Mixed} options Options object
570
- */
571
- setBranding(branding) {
572
- const previous = {
573
- brand: this.brand,
574
- application: this.application
575
- };
576
- if (
577
- branding &&
578
- branding.hasOwnProperty('brand') &&
579
- branding.brand &&
580
- typeof branding.brand === 'string'
581
- ) {
582
- this.brand = branding.brand;
583
- }
584
- if (
585
- branding &&
586
- branding.hasOwnProperty('application') &&
587
- branding.application &&
588
- typeof branding.application === 'string'
589
- ) {
590
- this.application = branding.application;
591
- }
592
- this._constructHelpUrls(previous);
593
- }
594
- _constructHelpUrls(previous = null) {
595
- // TODO: es-modules-version
596
- var version = (axe.version.match(/^[1-9][0-9]*\.[0-9]+/) || ['x.y'])[0];
597
- this.rules.forEach(rule => {
598
- if (!this.data.rules[rule.id]) {
599
- this.data.rules[rule.id] = {};
600
- }
601
- const metaData = this.data.rules[rule.id];
602
- if (
603
- typeof metaData.helpUrl !== 'string' ||
604
- (previous &&
605
- metaData.helpUrl === getHelpUrl(previous, rule.id, version))
606
- ) {
607
- metaData.helpUrl = getHelpUrl(this, rule.id, version);
608
- }
609
- });
610
- }
611
- /**
612
- * Reset the default rules, checks and meta data
613
- */
614
- resetRulesAndChecks() {
615
- this._init();
616
- this._resetLocale();
617
- }
380
+ // TODO: es-modules_selectCache
381
+ axe._selectCache = [];
382
+ // get a list of rules to run NOW vs. LATER (later are preload assets dependent rules)
383
+ const allRulesToRun = getRulesToRun(this.rules, context, options);
384
+ const runNowRules = allRulesToRun.now;
385
+ const runLaterRules = allRulesToRun.later;
386
+ // init a NOW queue for rules to run immediately
387
+ const nowRulesQueue = queue();
388
+ // construct can run NOW rules into NOW queue
389
+ runNowRules.forEach(rule => {
390
+ nowRulesQueue.defer(getDefferedRule(rule, context, options));
391
+ });
392
+ // init a PRELOADER queue to start preloading assets
393
+ const preloaderQueue = queue();
394
+ // defer preload if preload dependent rules exist
395
+ if (runLaterRules.length) {
396
+ preloaderQueue.defer(resolve => {
397
+ // handle both success and fail of preload
398
+ // and resolve, to allow to run all checks
399
+ preload(options)
400
+ .then(assets => resolve(assets))
401
+ .catch(err => {
402
+ /**
403
+ * Note:
404
+ * we do not reject, to allow other (non-preload) rules to `run`
405
+ * -> instead we resolve as `undefined`
406
+ */
407
+ console.warn(`Couldn't load preload assets: `, err);
408
+ resolve(undefined);
409
+ });
410
+ });
411
+ }
412
+ // defer now and preload queue to run immediately
413
+ const queueForNowRulesAndPreloader = queue();
414
+ queueForNowRulesAndPreloader.defer(nowRulesQueue);
415
+ queueForNowRulesAndPreloader.defer(preloaderQueue);
416
+ // invoke the now queue
417
+ queueForNowRulesAndPreloader
418
+ .then(nowRulesAndPreloaderResults => {
419
+ // interpolate results into separate variables
420
+ const assetsFromQueue = nowRulesAndPreloaderResults.pop();
421
+ if (assetsFromQueue && assetsFromQueue.length) {
422
+ // result is a queue (again), hence the index resolution
423
+ // assets is either an object of key value pairs of asset type and values
424
+ // eg: cssom: [stylesheets]
425
+ // or undefined if preload failed
426
+ const assets = assetsFromQueue[0];
427
+ // extend context with preloaded assets
428
+ if (assets) {
429
+ context = {
430
+ ...context,
431
+ ...assets
432
+ };
433
+ }
434
+ }
435
+ // the reminder of the results are RuleResults
436
+ const nowRulesResults = nowRulesAndPreloaderResults[0];
437
+ // if there are no rules to run LATER - resolve with rule results
438
+ if (!runLaterRules.length) {
439
+ // remove the cache
440
+ axe._selectCache = undefined;
441
+ // resolve
442
+ resolve(nowRulesResults.filter(result => !!result));
443
+ return;
444
+ }
445
+ // init a LATER queue for rules that are dependant on preloaded assets
446
+ const laterRulesQueue = queue();
447
+ runLaterRules.forEach(rule => {
448
+ const deferredRule = getDefferedRule(rule, context, options);
449
+ laterRulesQueue.defer(deferredRule);
450
+ });
451
+ // invoke the later queue
452
+ laterRulesQueue
453
+ .then(laterRuleResults => {
454
+ // remove the cache
455
+ axe._selectCache = undefined;
456
+ // resolve
457
+ resolve(
458
+ nowRulesResults
459
+ .concat(laterRuleResults)
460
+ .filter(result => !!result)
461
+ );
462
+ })
463
+ .catch(reject);
464
+ })
465
+ .catch(reject);
466
+ }
467
+ /**
468
+ * Runs Rule `after` post processing functions
469
+ * @param {Array} results Array of RuleResults to postprocess
470
+ * @param {Mixed} options Options object to pass into rules and/or disable rules or checks
471
+ */
472
+ after(results, options) {
473
+ var rules = this.rules;
474
+ return results.map(function(ruleResult) {
475
+ var rule = findBy(rules, 'id', ruleResult.id);
476
+ if (!rule) {
477
+ // If you see this, you're probably running the Mocha tests with the axe extension installed
478
+ throw new Error(
479
+ 'Result for unknown rule. You may be running mismatch axe-core versions'
480
+ );
481
+ }
482
+ return rule.after(ruleResult, options);
483
+ });
484
+ }
485
+ /**
486
+ * Get the rule with a given ID
487
+ * @param {string}
488
+ * @return {Rule}
489
+ */
490
+ getRule(ruleId) {
491
+ return this.rules.find(rule => rule.id === ruleId);
492
+ }
493
+ /**
494
+ * Ensure all rules that are expected to run exist
495
+ * @throws {Error} If any tag or rule specified in options is unknown
496
+ * @param {Object} options Options object
497
+ * @return {Object} Validated options object
498
+ */
499
+ normalizeOptions(options) {
500
+ var audit = this;
501
+ const tags = [];
502
+ const ruleIds = [];
503
+ audit.rules.forEach(rule => {
504
+ ruleIds.push(rule.id);
505
+ rule.tags.forEach(tag => {
506
+ if (!tags.includes(tag)) {
507
+ tags.push(tag);
508
+ }
509
+ });
510
+ });
511
+ // Validate runOnly
512
+ if (typeof options.runOnly === 'object') {
513
+ if (Array.isArray(options.runOnly)) {
514
+ const hasTag = options.runOnly.find(value => tags.includes(value));
515
+ const hasRule = options.runOnly.find(value => ruleIds.includes(value));
516
+ if (hasTag && hasRule) {
517
+ throw new Error('runOnly cannot be both rules and tags');
518
+ }
519
+ if (hasRule) {
520
+ options.runOnly = {
521
+ type: 'rule',
522
+ values: options.runOnly
523
+ };
524
+ } else {
525
+ options.runOnly = {
526
+ type: 'tag',
527
+ values: options.runOnly
528
+ };
529
+ }
530
+ }
531
+ const only = options.runOnly;
532
+ if (only.value && !only.values) {
533
+ only.values = only.value;
534
+ delete only.value;
535
+ }
536
+ if (!Array.isArray(only.values) || only.values.length === 0) {
537
+ throw new Error('runOnly.values must be a non-empty array');
538
+ }
539
+ // Check if every value in options.runOnly is a known rule ID
540
+ if (['rule', 'rules'].includes(only.type)) {
541
+ only.type = 'rule';
542
+ only.values.forEach(function(ruleId) {
543
+ if (!ruleIds.includes(ruleId)) {
544
+ throw new Error('unknown rule `' + ruleId + '` in options.runOnly');
545
+ }
546
+ });
547
+ // Validate 'tags' (e.g. anything not 'rule')
548
+ } else if (['tag', 'tags', undefined].includes(only.type)) {
549
+ only.type = 'tag';
550
+ const unmatchedTags = only.values.filter(tag => !tags.includes(tag));
551
+ if (unmatchedTags.length !== 0) {
552
+ log('Could not find tags `' + unmatchedTags.join('`, `') + '`');
553
+ }
554
+ } else {
555
+ throw new Error(`Unknown runOnly type '${only.type}'`);
556
+ }
557
+ }
558
+ if (typeof options.rules === 'object') {
559
+ Object.keys(options.rules).forEach(function(ruleId) {
560
+ if (!ruleIds.includes(ruleId)) {
561
+ throw new Error('unknown rule `' + ruleId + '` in options.rules');
562
+ }
563
+ });
564
+ }
565
+ return options;
566
+ }
567
+ /*
568
+ * Updates the default options and then applies them
569
+ * @param {Mixed} options Options object
570
+ */
571
+ setBranding(branding) {
572
+ let previous = {
573
+ brand: this.brand,
574
+ application: this.application
575
+ };
576
+ if (
577
+ branding &&
578
+ branding.hasOwnProperty('brand') &&
579
+ branding.brand &&
580
+ typeof branding.brand === 'string'
581
+ ) {
582
+ this.brand = branding.brand;
583
+ }
584
+ if (
585
+ branding &&
586
+ branding.hasOwnProperty('application') &&
587
+ branding.application &&
588
+ typeof branding.application === 'string'
589
+ ) {
590
+ this.application = branding.application;
591
+ }
592
+ this._constructHelpUrls(previous);
593
+ }
594
+ _constructHelpUrls(previous = null) {
595
+ // TODO: es-modules-version
596
+ var version = (axe.version.match(/^[1-9][0-9]*\.[0-9]+/) || ['x.y'])[0];
597
+ this.rules.forEach(rule => {
598
+ if (!this.data.rules[rule.id]) {
599
+ this.data.rules[rule.id] = {};
600
+ }
601
+ let metaData = this.data.rules[rule.id];
602
+ if (
603
+ typeof metaData.helpUrl !== 'string' ||
604
+ (previous &&
605
+ metaData.helpUrl === getHelpUrl(previous, rule.id, version))
606
+ ) {
607
+ metaData.helpUrl = getHelpUrl(this, rule.id, version);
608
+ }
609
+ });
610
+ }
611
+ /**
612
+ * Reset the default rules, checks and meta data
613
+ */
614
+ resetRulesAndChecks() {
615
+ this._init();
616
+ this._resetLocale();
617
+ }
618
618
  }
619
619
 
620
620
  /**
@@ -627,34 +627,34 @@ class Audit {
627
627
  * @private
628
628
  */
629
629
  function getRulesToRun(rules, context, options) {
630
- // entry object for reduce function below
631
- const base = {
632
- now: [],
633
- later: []
634
- };
630
+ // entry object for reduce function below
631
+ const base = {
632
+ now: [],
633
+ later: []
634
+ };
635
635
 
636
- // iterate through rules and separate out rules that need to be run now vs later
637
- const splitRules = rules.reduce((out, rule) => {
638
- // ensure rule can run
639
- if (!ruleShouldRun(rule, context, options)) {
640
- return out;
641
- }
636
+ // iterate through rules and separate out rules that need to be run now vs later
637
+ const splitRules = rules.reduce((out, rule) => {
638
+ // ensure rule can run
639
+ if (!ruleShouldRun(rule, context, options)) {
640
+ return out;
641
+ }
642
642
 
643
- // does rule require preload assets - push to later array
644
- if (rule.preload) {
645
- out.later.push(rule);
646
- return out;
647
- }
643
+ // does rule require preload assets - push to later array
644
+ if (rule.preload) {
645
+ out.later.push(rule);
646
+ return out;
647
+ }
648
648
 
649
- // default to now array
650
- out.now.push(rule);
649
+ // default to now array
650
+ out.now.push(rule);
651
651
 
652
- // return
653
- return out;
654
- }, base);
652
+ // return
653
+ return out;
654
+ }, base);
655
655
 
656
- // return
657
- return splitRules;
656
+ // return
657
+ return splitRules;
658
658
  }
659
659
 
660
660
  /**
@@ -666,61 +666,61 @@ function getRulesToRun(rules, context, options) {
666
666
  * @return {Function} a deferrable function for rule
667
667
  */
668
668
  function getDefferedRule(rule, context, options) {
669
- // init performance timer of requested via options
670
- if (options.performanceTimer) {
671
- performanceTimer.mark('mark_rule_start_' + rule.id);
672
- }
669
+ // init performance timer of requested via options
670
+ if (options.performanceTimer) {
671
+ performanceTimer.mark('mark_rule_start_' + rule.id);
672
+ }
673
673
 
674
- return (resolve, reject) => {
675
- // invoke `rule.run`
676
- rule.run(
677
- context,
678
- options,
679
- // resolve callback for rule `run`
680
- ruleResult => {
681
- // resolve
682
- resolve(ruleResult);
683
- },
684
- // reject callback for rule `run`
685
- err => {
686
- // if debug - construct error details
687
- if (!options.debug) {
688
- const errResult = Object.assign(new RuleResult(rule), {
689
- result: constants.CANTTELL,
690
- description: 'An error occured while running this rule',
691
- message: err.message,
692
- stack: err.stack,
693
- error: err,
694
- // Add a serialized reference to the node the rule failed on for easier debugging.
695
- // See https://github.com/dequelabs/axe-core/issues/1317.
696
- errorNode: err.errorNode
697
- });
698
- // resolve
699
- resolve(errResult);
700
- } else {
701
- // reject
702
- reject(err);
703
- }
704
- }
705
- );
706
- };
674
+ return (resolve, reject) => {
675
+ // invoke `rule.run`
676
+ rule.run(
677
+ context,
678
+ options,
679
+ // resolve callback for rule `run`
680
+ ruleResult => {
681
+ // resolve
682
+ resolve(ruleResult);
683
+ },
684
+ // reject callback for rule `run`
685
+ err => {
686
+ // if debug - construct error details
687
+ if (!options.debug) {
688
+ const errResult = Object.assign(new RuleResult(rule), {
689
+ result: constants.CANTTELL,
690
+ description: 'An error occured while running this rule',
691
+ message: err.message,
692
+ stack: err.stack,
693
+ error: err,
694
+ // Add a serialized reference to the node the rule failed on for easier debugging.
695
+ // See https://github.com/dequelabs/axe-core/issues/1317.
696
+ errorNode: err.errorNode
697
+ });
698
+ // resolve
699
+ resolve(errResult);
700
+ } else {
701
+ // reject
702
+ reject(err);
703
+ }
704
+ }
705
+ );
706
+ };
707
707
  }
708
708
 
709
709
  /**
710
710
  * For all the rules, create the helpUrl and add it to the data for that rule
711
711
  */
712
712
  function getHelpUrl({ brand, application, lang }, ruleId, version) {
713
- return (
714
- constants.helpUrlBase +
715
- brand +
716
- '/' +
717
- (version || axe.version.substring(0, axe.version.lastIndexOf('.'))) +
718
- '/' +
719
- ruleId +
720
- '?application=' +
721
- encodeURIComponent(application) +
722
- (lang && lang !== 'en' ? '&lang=' + encodeURIComponent(lang) : '')
723
- );
713
+ return (
714
+ constants.helpUrlBase +
715
+ brand +
716
+ '/' +
717
+ (version || axe.version.substring(0, axe.version.lastIndexOf('.'))) +
718
+ '/' +
719
+ ruleId +
720
+ '?application=' +
721
+ encodeURIComponent(application) +
722
+ (lang && lang !== 'en' ? '&lang=' + encodeURIComponent(lang) : '')
723
+ );
724
724
  }
725
725
 
726
726
  export default Audit;