@@ -10,69 +10,28 @@ function create (context) {
1010 const options = context . options [ 0 ] || { }
1111 const treatUndefinedAsUnspecified = ! ( options . treatUndefinedAsUnspecified === false )
1212
13- let funcInfo = {
14- funcInfo : null ,
15- codePath : null ,
16- hasReturn : false ,
17- hasReturnValue : false ,
18- node : null
19- }
2013 const forbiddenNodes = [ ]
2114
22- // ----------------------------------------------------------------------
23- // Helpers
24- // ----------------------------------------------------------------------
25- function isValidReturn ( ) {
26- if ( ! funcInfo . hasReturn ) {
27- return false
28- }
29- return ! treatUndefinedAsUnspecified || funcInfo . hasReturnValue
30- }
31-
3215 // ----------------------------------------------------------------------
3316 // Public
3417 // ----------------------------------------------------------------------
3518
3619 return Object . assign ( { } ,
37- {
38- onCodePathStart ( codePath , node ) {
39- funcInfo = {
40- codePath,
41- funcInfo : funcInfo ,
42- hasReturn : false ,
43- hasReturnValue : false ,
44- node
45- }
46- } ,
47- onCodePathEnd ( ) {
48- funcInfo = funcInfo . funcInfo
49- } ,
50- ReturnStatement ( node ) {
51- funcInfo . hasReturn = true
52- funcInfo . hasReturnValue = Boolean ( node . argument )
53- } ,
54- 'FunctionExpression:exit' ( node ) {
55- if ( ! isValidReturn ( ) ) {
56- forbiddenNodes . push ( {
57- hasReturn : funcInfo . hasReturn ,
58- node : funcInfo . node ,
59- type : 'return'
60- } )
61- }
62- }
63- } ,
20+ utils . executeOnFunctionsWithoutReturn ( treatUndefinedAsUnspecified , node => {
21+ forbiddenNodes . push ( node )
22+ } ) ,
6423 utils . executeOnVue ( context , properties => {
6524 const computedProperties = utils . getComputedProperties ( properties )
6625
6726 computedProperties . forEach ( cp => {
6827 forbiddenNodes . forEach ( el => {
6928 if (
7029 cp . value &&
71- el . node . loc . start . line >= cp . value . loc . start . line &&
72- el . node . loc . end . line <= cp . value . loc . end . line
30+ el . loc . start . line >= cp . value . loc . start . line &&
31+ el . loc . end . line <= cp . value . loc . end . line
7332 ) {
7433 context . report ( {
75- node : el . node ,
34+ node : el ,
7635 message : 'Expected to return a value in "{{name}}" computed property.' ,
7736 data : {
7837 name : cp . key
0 commit comments