6
6
'use strict' ;
7
7
8
8
const docsUrl = require ( '../util/docsUrl' ) ;
9
+ const linkComponentsUtil = require ( '../util/linkComponents' ) ;
9
10
const report = require ( '../util/report' ) ;
10
11
11
12
// ------------------------------------------------------------------------------
@@ -22,25 +23,25 @@ function hasJavaScriptProtocol(attr) {
22
23
}
23
24
24
25
function shouldVerifyElement ( node , config ) {
25
- const name = node . name && node . name . name ;
26
- return name === 'a' || config . find ( ( i ) => i . name === name ) ;
26
+ const name = node . name && node . name . name
27
+ return name ? config . has ( name ) : false
27
28
}
28
29
29
30
function shouldVerifyProp ( node , config ) {
30
31
const name = node . name && node . name . name ;
31
32
const parentName = node . parent . name && node . parent . name . name ;
32
33
33
- if ( parentName === 'a' && name === 'href' ) {
34
- return true ;
35
- }
36
-
37
- const el = config . find ( ( i ) => i . name === parentName ) ;
38
- if ( ! el ) {
39
- return false ;
40
- }
34
+ return ( name && parentName ) ? name === config . get ( parentName ) : false
35
+ }
41
36
42
- const props = el . props || [ ] ;
43
- return node . name && props . indexOf ( name ) !== - 1 ;
37
+ function parseLegacyOption ( option ) {
38
+ const config = linkComponentsUtil . getLinkComponents ( { } ) // get defaults
39
+ option . forEach ( function ( opt ) {
40
+ opt . props . forEach ( function ( prop ) { // FIXME: only last prop will work at the moment
41
+ config . set ( opt . name , prop )
42
+ } )
43
+ } )
44
+ return config
44
45
}
45
46
46
47
const messages = {
@@ -77,16 +78,18 @@ module.exports = {
77
78
} ,
78
79
required : [ 'name' , 'props' ] ,
79
80
additionalProperties : false ,
81
+ deprecated : true , // ?
80
82
} ,
81
83
} ] ,
82
84
} ,
83
85
84
86
create ( context ) {
85
- const config = context . options [ 0 ] || [ ] ;
87
+ const linkComponents = context . options [ 0 ] ? parseLegacyOption ( context . options [ 0 ] ) : linkComponentsUtil . getLinkComponents ( context ) ;
88
+
86
89
return {
87
90
JSXAttribute ( node ) {
88
91
const parent = node . parent ;
89
- if ( shouldVerifyElement ( parent , config ) && shouldVerifyProp ( node , config ) && hasJavaScriptProtocol ( node ) ) {
92
+ if ( shouldVerifyElement ( parent , linkComponents ) && shouldVerifyProp ( node , linkComponents ) && hasJavaScriptProtocol ( node ) ) {
90
93
report ( context , messages . noScriptURL , 'noScriptURL' , {
91
94
node,
92
95
} ) ;
0 commit comments