@@ -73,7 +73,7 @@ module.exports = {
7373
7474 create ( context ) {
7575 const forbiddenNodes = [ ]
76- const allowedScopes = [ ]
76+ let scopeStack = { upper : null , body : null }
7777
7878 const expressionTypes = {
7979 promise : 'asynchronous action' ,
@@ -87,65 +87,54 @@ module.exports = {
8787 if ( node . async ) {
8888 forbiddenNodes . push ( {
8989 node : node ,
90- type : 'async'
90+ type : 'async' ,
91+ targetBody : node . body
9192 } )
92- } else if ( node . parent . type === 'ReturnStatement' ) {
93- allowedScopes . push ( node )
9493 }
94+
95+ scopeStack = { upper : scopeStack , body : node . body }
9596 }
9697
98+ function onFunctionExit ( ) {
99+ scopeStack = scopeStack . upper
100+ }
97101 return Object . assign ( { } ,
98102 {
99- FunctionDeclaration : onFunctionEnter ,
100-
101- FunctionExpression : onFunctionEnter ,
102-
103- ArrowFunctionExpression : onFunctionEnter ,
103+ ':function' : onFunctionEnter ,
104+ ':function:exit' : onFunctionExit ,
104105
105106 NewExpression ( node ) {
106107 if ( node . callee . name === 'Promise' ) {
107108 forbiddenNodes . push ( {
108109 node : node ,
109- type : 'new'
110+ type : 'new' ,
111+ targetBody : scopeStack . body
110112 } )
111- } else if ( node . parent . type === 'ReturnStatement' ) {
112- allowedScopes . push ( node )
113113 }
114114 } ,
115115
116116 CallExpression ( node ) {
117117 if ( isPromise ( node ) ) {
118118 forbiddenNodes . push ( {
119119 node : node ,
120- type : 'promise'
120+ type : 'promise' ,
121+ targetBody : scopeStack . body
121122 } )
122123 } else if ( isTimedFunction ( node ) ) {
123124 forbiddenNodes . push ( {
124125 node : node ,
125- type : 'timed'
126+ type : 'timed' ,
127+ targetBody : scopeStack . body
126128 } )
127- } else if ( node . parent . type === 'ReturnStatement' ) {
128- allowedScopes . push ( node )
129129 }
130130 } ,
131131
132132 AwaitExpression ( node ) {
133133 forbiddenNodes . push ( {
134134 node : node ,
135- type : 'await'
135+ type : 'await' ,
136+ targetBody : scopeStack . body
136137 } )
137- } ,
138-
139- 'ReturnStatement' ( node ) {
140- if (
141- node . argument &&
142- (
143- node . argument . type === 'ObjectExpression' ||
144- node . argument . type === 'ArrayExpression'
145- )
146- ) {
147- allowedScopes . push ( node . argument )
148- }
149138 }
150139 } ,
151140 utils . executeOnVue ( context , ( obj ) => {
@@ -157,10 +146,7 @@ module.exports = {
157146 cp . value &&
158147 el . node . loc . start . line >= cp . value . loc . start . line &&
159148 el . node . loc . end . line <= cp . value . loc . end . line &&
160- ! allowedScopes . some ( scope =>
161- scope . range [ 0 ] < el . node . range [ 0 ] &&
162- scope . range [ 1 ] > el . node . range [ 1 ]
163- )
149+ el . targetBody === cp . value
164150 ) {
165151 context . report ( {
166152 node : el . node ,
0 commit comments