1- export function scanForProblems ( context , logError , options ) {
1+ export function scanForProblems ( context , errorCallback , options ) {
2+ const errors = { }
3+
4+ function logError ( err ) {
5+ const { name} = err
6+
7+ errors [ name ] = errors [ name ] || [ ]
8+ errors [ name ] . push ( err )
9+
10+ errorCallback ( err )
11+ }
12+
213 for ( const img of context . querySelectorAll ( 'img' ) ) {
314 if ( ! img . hasAttribute ( 'alt' ) ) {
415 logError ( new ImageWithoutAltAttributeError ( img ) )
@@ -31,9 +42,13 @@ export function scanForProblems(context, logError, options) {
3142 }
3243 }
3344
34- for ( const input of context . querySelectorAll ( 'input[type=text], input[type=url], input[type=search], input[type=number], textarea' ) ) {
45+ for ( const input of context . querySelectorAll (
46+ 'input[type=text], input[type=url], input[type=search], input[type=number], textarea'
47+ ) ) {
3548 // In case input.labels isn't supported by browser, find the control manually (IE)
36- const inputLabel = input . labels ? input . labels [ 0 ] : input . closest ( 'label' ) || document . querySelector ( `label[for="${ input . id } "]` )
49+ const inputLabel = input . labels
50+ ? input . labels [ 0 ]
51+ : input . closest ( 'label' ) || document . querySelector ( `label[for="${ input . id } "]` )
3752 if ( ! inputLabel && ! elementIsHidden ( input ) && ! input . hasAttribute ( 'aria-label' ) ) {
3853 logError ( new InputMissingLabelError ( input ) )
3954 }
@@ -47,7 +62,7 @@ export function scanForProblems(context, logError, options) {
4762
4863 if ( options && options [ 'ariaPairs' ] ) {
4964 for ( const selector in options [ 'ariaPairs' ] ) {
50- const ARIAAttrsRequired = options [ 'ariaPairs' ] [ selector ]
65+ const ARIAAttrsRequired = options [ 'ariaPairs' ] [ selector ]
5166 for ( const target of context . querySelectorAll ( selector ) ) {
5267 const missingAttrs = [ ]
5368
@@ -61,6 +76,8 @@ export function scanForProblems(context, logError, options) {
6176 }
6277 }
6378 }
79+
80+ return errors
6481}
6582
6683function errorSubclass ( fn ) {
@@ -157,7 +174,12 @@ function isText(value) {
157174function accessibleText ( node ) {
158175 switch ( node . nodeType ) {
159176 case Node . ELEMENT_NODE :
160- if ( isText ( node . getAttribute ( 'alt' ) ) || isText ( node . getAttribute ( 'aria-label' ) ) || isText ( node . getAttribute ( 'title' ) ) ) return true
177+ if (
178+ isText ( node . getAttribute ( 'alt' ) ) ||
179+ isText ( node . getAttribute ( 'aria-label' ) ) ||
180+ isText ( node . getAttribute ( 'title' ) )
181+ )
182+ return true
161183 for ( let i = 0 ; i < node . childNodes . length ; i ++ ) {
162184 if ( accessibleText ( node . childNodes [ i ] ) ) return true
163185 }
0 commit comments