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
// ------------------------------------------------------------------------------
@@ -21,26 +22,21 @@ function hasJavaScriptProtocol(attr) {
21
22
&& isJavaScriptProtocol . test ( attr . value . value ) ;
22
23
}
23
24
24
- function shouldVerifyElement ( node , config ) {
25
- const name = node . name && node . name . name ;
26
- return name === 'a' || config . find ( ( i ) => i . name === name ) ;
27
- }
28
-
29
25
function shouldVerifyProp ( node , config ) {
30
26
const name = node . name && node . name . name ;
31
27
const parentName = node . parent . name && node . parent . name . name ;
32
28
33
- if ( parentName === 'a' && name === 'href' ) {
34
- return true ;
35
- }
29
+ if ( ! name || ! parentName || ! config . has ( parentName ) ) return false ;
36
30
37
- const el = config . find ( ( i ) => i . name === parentName ) ;
38
- if ( ! el ) {
39
- return false ;
40
- }
31
+ return name === config . get ( parentName ) ;
32
+ }
41
33
42
- const props = el . props || [ ] ;
43
- return node . name && props . indexOf ( name ) !== - 1 ;
34
+ function parseLegacyOption ( config , option ) {
35
+ option . forEach ( ( opt ) => {
36
+ opt . props . forEach ( ( prop ) => {
37
+ config . set ( opt . name , prop ) ;
38
+ } ) ;
39
+ } ) ;
44
40
}
45
41
46
42
const messages = {
@@ -82,11 +78,14 @@ module.exports = {
82
78
} ,
83
79
84
80
create ( context ) {
85
- const config = context . options [ 0 ] || [ ] ;
81
+ const linkComponents = linkComponentsUtil . getLinkComponents ( context ) ;
82
+ if ( context . options [ 0 ] ) {
83
+ parseLegacyOption ( linkComponents , context . options [ 0 ] ) ;
84
+ }
85
+
86
86
return {
87
87
JSXAttribute ( node ) {
88
- const parent = node . parent ;
89
- if ( shouldVerifyElement ( parent , config ) && shouldVerifyProp ( node , config ) && hasJavaScriptProtocol ( node ) ) {
88
+ if ( shouldVerifyProp ( node , linkComponents ) && hasJavaScriptProtocol ( node ) ) {
90
89
report ( context , messages . noScriptURL , 'noScriptURL' , {
91
90
node,
92
91
} ) ;
0 commit comments