@@ -10,69 +10,28 @@ function create (context) {
10
10
const options = context . options [ 0 ] || { }
11
11
const treatUndefinedAsUnspecified = ! ( options . treatUndefinedAsUnspecified === false )
12
12
13
- let funcInfo = {
14
- funcInfo : null ,
15
- codePath : null ,
16
- hasReturn : false ,
17
- hasReturnValue : false ,
18
- node : null
19
- }
20
13
const forbiddenNodes = [ ]
21
14
22
- // ----------------------------------------------------------------------
23
- // Helpers
24
- // ----------------------------------------------------------------------
25
- function isValidReturn ( ) {
26
- if ( ! funcInfo . hasReturn ) {
27
- return false
28
- }
29
- return ! treatUndefinedAsUnspecified || funcInfo . hasReturnValue
30
- }
31
-
32
15
// ----------------------------------------------------------------------
33
16
// Public
34
17
// ----------------------------------------------------------------------
35
18
36
19
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
+ } ) ,
64
23
utils . executeOnVue ( context , properties => {
65
24
const computedProperties = utils . getComputedProperties ( properties )
66
25
67
26
computedProperties . forEach ( cp => {
68
27
forbiddenNodes . forEach ( el => {
69
28
if (
70
29
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
73
32
) {
74
33
context . report ( {
75
- node : el . node ,
34
+ node : el ,
76
35
message : 'Expected to return a value in "{{name}}" computed property.' ,
77
36
data : {
78
37
name : cp . key
0 commit comments