File tree Expand file tree Collapse file tree 4 files changed +1209
-640
lines changed Expand file tree Collapse file tree 4 files changed +1209
-640
lines changed Original file line number Diff line number Diff line change 55
66'use strict' ;
77
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+
826module . exports = ( context ) => {
927 const options = context . options [ 0 ] || { } ;
1028
11- const elementName = ( node ) => (
12- node . openingElement
13- && node . openingElement . name
14- && node . openingElement . name . type === 'JSXIdentifier'
15- && node . openingElement . name . name
16- ) ;
17-
1829 const report = ( node ) => {
1930 const errorValue = node . type === 'TemplateLiteral'
2031 ? `TemplateLiteral: ${ node . expressions [ 0 ] . name } `
@@ -35,7 +46,8 @@ module.exports = (context) => {
3546
3647 const hasOnlyLineBreak = ( value ) => / ^ [ \r \n \t \f \v ] + $ / . test ( value . replace ( / / g, '' ) ) ;
3748
38- const getValidation = ( node ) => ! allowedElements . includes ( elementName ( node . parent ) ) ;
49+ const scope = context . getScope ( ) ;
50+ const getValidation = ( node ) => ! allowedElements . includes ( elementName ( node . parent , scope ) ) ;
3951
4052 return {
4153 Literal ( node ) {
Original file line number Diff line number Diff line change 4848 ],
4949 "license" : " MIT" ,
5050 "dependencies" : {
51+ "@babel/traverse" : " ^7.7.4" ,
5152 "eslint-plugin-react-native-globals" : " ^0.1.1"
5253 }
5354}
Original file line number Diff line number Diff line change @@ -97,6 +97,14 @@ const tests = {
9797 ` ,
9898 options : [ { skip : [ 'Title' ] } ] ,
9999 } ,
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+ } ,
100108 ] ,
101109 invalid : [
102110 {
@@ -158,6 +166,16 @@ const tests = {
158166 message : 'Raw text (some text) cannot be used outside of a <Text> tag' ,
159167 } ] ,
160168 } ,
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+ } ,
161179 ] ,
162180} ;
163181
You can’t perform that action at this time.
0 commit comments