File tree 4 files changed +1209
-640
lines changed 4 files changed +1209
-640
lines changed Original file line number Diff line number Diff line change 5
5
6
6
'use strict' ;
7
7
8
+ const { default : traverse } = require ( '@babel/traverse' ) ;
9
+
10
+ const elementName = ( node , scope ) => {
11
+ const identifiers = [ ] ;
12
+
13
+ traverse ( node , {
14
+ JSXOpeningElement ( { node : element } ) {
15
+ traverse ( element , {
16
+ JSXIdentifier ( { node : identifier } ) {
17
+ identifiers . push ( identifier . name ) ;
18
+ } ,
19
+ } , scope ) ;
20
+ } ,
21
+ } , scope ) ;
22
+
23
+ return identifiers . join ( '.' ) ;
24
+ } ;
25
+
8
26
module . exports = ( context ) => {
9
27
const options = context . options [ 0 ] || { } ;
10
28
11
- const elementName = ( node ) => (
12
- node . openingElement
13
- && node . openingElement . name
14
- && node . openingElement . name . type === 'JSXIdentifier'
15
- && node . openingElement . name . name
16
- ) ;
17
-
18
29
const report = ( node ) => {
19
30
const errorValue = node . type === 'TemplateLiteral'
20
31
? `TemplateLiteral: ${ node . expressions [ 0 ] . name } `
@@ -35,7 +46,8 @@ module.exports = (context) => {
35
46
36
47
const hasOnlyLineBreak = ( value ) => / ^ [ \r \n \t \f \v ] + $ / . test ( value . replace ( / / g, '' ) ) ;
37
48
38
- const getValidation = ( node ) => ! allowedElements . includes ( elementName ( node . parent ) ) ;
49
+ const scope = context . getScope ( ) ;
50
+ const getValidation = ( node ) => ! allowedElements . includes ( elementName ( node . parent , scope ) ) ;
39
51
40
52
return {
41
53
Literal ( node ) {
Original file line number Diff line number Diff line change 48
48
],
49
49
"license" : " MIT" ,
50
50
"dependencies" : {
51
+ "@babel/traverse" : " ^7.7.4" ,
51
52
"eslint-plugin-react-native-globals" : " ^0.1.1"
52
53
}
53
54
}
Original file line number Diff line number Diff line change @@ -97,6 +97,14 @@ const tests = {
97
97
` ,
98
98
options : [ { skip : [ 'Title' ] } ] ,
99
99
} ,
100
+ {
101
+ code : `
102
+ const Title = ({ children }) => (<Title.Text>{children}</Title.Text>);
103
+ Title.Text = ({ children }) => (<Text>{children}</Text>);
104
+ <Title.Text>This is the title</Title.Text>
105
+ ` ,
106
+ options : [ { skip : [ 'Title.Text' ] } ] ,
107
+ } ,
100
108
] ,
101
109
invalid : [
102
110
{
@@ -158,6 +166,16 @@ const tests = {
158
166
message : 'Raw text (some text) cannot be used outside of a <Text> tag' ,
159
167
} ] ,
160
168
} ,
169
+ {
170
+ code : `
171
+ const Component = ({ children }) => (<Text>{children}</Text>);
172
+ <Component>some text</Component>
173
+ ` ,
174
+ options : [ { skip : [ 'Component.Text' ] } ] ,
175
+ errors : [ {
176
+ message : 'Raw text (some text) cannot be used outside of a <Text> tag' ,
177
+ } ] ,
178
+ } ,
161
179
] ,
162
180
} ;
163
181
You can’t perform that action at this time.
0 commit comments