File tree Expand file tree Collapse file tree 2 files changed +100
-1
lines changed Expand file tree Collapse file tree 2 files changed +100
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,30 @@ export default iterateJsdoc(({
14
14
15
15
const sourcecode = utils . getFunctionSourceCode ( ) ;
16
16
17
- if ( JSON . stringify ( jsdocTags ) === '[]' && sourcecode . indexOf ( 'return' ) >= 1 ) {
17
+ // build a one-liner to test against
18
+ const flattenedSource = sourcecode . replace ( / \r ? \n | \r | \s / g, '' ) ;
19
+
20
+ const startsWithReturn = '(\\)\\s?\\{return)' ;
21
+
22
+ const endsWithReturn = '(return.*\\})' ;
23
+
24
+ const implicitReturn = '(\\s?=>\\s?\\b.*)' ;
25
+
26
+ const implicitObjectReturn = '(\\s?=>\\s?\\(\\{)' ;
27
+
28
+ const matcher = new RegExp ( [
29
+ startsWithReturn ,
30
+ endsWithReturn ,
31
+ implicitObjectReturn ,
32
+ implicitReturn
33
+ ] . join ( '|' ) , 'gim' ) ;
34
+
35
+ const positiveTest = ( flattenedSource . match ( matcher ) || [ ] ) . length > 0 ;
36
+
37
+ const negativeTest = ( flattenedSource . match ( / ( \{ .* \{ .* r e t u r n ) / gim) || [ ] ) . length > 0 &&
38
+ ( flattenedSource . match ( / ( r e t u r n ) / gim) || [ ] ) . length < 2 ;
39
+
40
+ if ( JSON . stringify ( jsdocTags ) === '[]' && positiveTest && ! negativeTest ) {
18
41
report ( 'Missing JSDoc @' + targetTagName + ' declaration.' ) ;
19
42
}
20
43
} ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,50 @@ export default {
17
17
}
18
18
]
19
19
} ,
20
+ {
21
+ code : `
22
+ /**
23
+ *
24
+ */
25
+ const foo = () => ({
26
+ bar: 'baz'
27
+ })
28
+ ` ,
29
+ errors : [
30
+ {
31
+ line : 2 ,
32
+ message : 'Missing JSDoc @returns declaration.'
33
+ }
34
+ ]
35
+ } ,
36
+ {
37
+ code : `
38
+ /**
39
+ *
40
+ */
41
+ const foo = bar=>({ bar })
42
+ ` ,
43
+ errors : [
44
+ {
45
+ line : 2 ,
46
+ message : 'Missing JSDoc @returns declaration.'
47
+ }
48
+ ]
49
+ } ,
50
+ {
51
+ code : `
52
+ /**
53
+ *
54
+ */
55
+ const foo = bar => bar.baz()
56
+ ` ,
57
+ errors : [
58
+ {
59
+ line : 2 ,
60
+ message : 'Missing JSDoc @returns declaration.'
61
+ }
62
+ ]
63
+ } ,
20
64
{
21
65
code : `
22
66
/**
@@ -62,6 +106,38 @@ export default {
62
106
function quux () {
63
107
}
64
108
`
109
+ } ,
110
+ {
111
+ code : `
112
+ /**
113
+ *
114
+ */
115
+ function quux (bar) {
116
+ bar.filter(baz => {
117
+ return baz.corge();
118
+ })
119
+ }
120
+ `
121
+ } ,
122
+ {
123
+ code : `
124
+ /**
125
+ * @returns Array
126
+ */
127
+ function quux (bar) {
128
+ return bar.filter(baz => {
129
+ return baz.corge();
130
+ })
131
+ }
132
+ `
133
+ } ,
134
+ {
135
+ code : `
136
+ /**
137
+ * @returns Array
138
+ */
139
+ const quux = (bar) => bar.filter(({ corge }) => corge())
140
+ `
65
141
}
66
142
]
67
143
} ;
You can’t perform that action at this time.
0 commit comments