File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -2257,6 +2257,12 @@ function quux (foo) {
2257
2257
}
2258
2258
// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
2259
2259
// Message: Present JSDoc @return declaration but not available return expression in function.
2260
+
2261
+ /**
2262
+ * @returns
2263
+ */
2264
+ const quux = () => {}
2265
+ // Message: Present JSDoc @returns declaration but not available return expression in function.
2260
2266
````
2261
2267
2262
2268
The following patterns are not considered problems:
@@ -2291,6 +2297,11 @@ function quux () {
2291
2297
*/
2292
2298
function quux () {
2293
2299
}
2300
+
2301
+ /**
2302
+ * @returns {*} Foo.
2303
+ */
2304
+ const quux = () => foo;
2294
2305
````
2295
2306
2296
2307
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import iterateJsdoc from '../iterateJsdoc';
4
4
export default iterateJsdoc ( ( {
5
5
jsdoc,
6
6
report,
7
+ functionNode,
7
8
utils
8
9
} ) => {
9
10
const targetTagName = utils . getPreferredTagName ( 'returns' ) ;
@@ -18,6 +19,11 @@ export default iterateJsdoc(({
18
19
return [ 'undefined' , 'void' ] . indexOf ( vundef . type ) !== - 1 ;
19
20
} ) === - 1 ;
20
21
22
+ // Implicit return like `() => foo` is ok
23
+ if ( functionNode . type === 'ArrowFunctionExpression' && functionNode . expression ) {
24
+ return ;
25
+ }
26
+
21
27
if ( JSON . stringify ( jsdocTags ) !== '[]' && voidReturn && sourcecode . indexOf ( 'return' ) < 1 ) {
22
28
report ( 'Present JSDoc @' + targetTagName + ' declaration but not available return expression in function.' ) ;
23
29
}
Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ export default {
38
38
}
39
39
}
40
40
}
41
+ } ,
42
+ {
43
+ code : `
44
+ /**
45
+ * @returns
46
+ */
47
+ const quux = () => {}
48
+ ` ,
49
+ errors : [
50
+ {
51
+ line : 2 ,
52
+ message : 'Present JSDoc @returns declaration but not available return expression in function.'
53
+ }
54
+ ]
41
55
}
42
56
] ,
43
57
valid : [
@@ -82,6 +96,14 @@ export default {
82
96
function quux () {
83
97
}
84
98
`
99
+ } ,
100
+ {
101
+ code : `
102
+ /**
103
+ * @returns {*} Foo.
104
+ */
105
+ const quux = () => foo;
106
+ `
85
107
}
86
108
]
87
109
} ;
You can’t perform that action at this time.
0 commit comments